Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

cbrt — C23 mathematical function

`cbrt(x)` from `<math.h>` takes a `double` and returns its real cube root; `cbrtf` and `cbrtl` provide the `float` and `long double` forms. A negative argument has a negative real result.

Version: C23

Syntax

double cbrt(double x);

cbrt(x) from <math.h> takes a double and returns its real cube root; cbrtf and cbrtl provide the float and long double forms. A negative argument has a negative real result.

Use it instead of pow(x, 1.0/3.0), especially for negative numbers. The example genuinely computes cbrt(-125.0) = -5 and cbrt(27.0) = 3, then prints both results.

Finite negative arguments do not cause a domain error; the result is limited by the type’s precision and can be rounded. Under Annex F/IEC 60559, cbrt(±0) preserves the zero sign and cbrt(±∞) returns the corresponding infinity.

Examples

#include <math.h>
#include <stdio.h>

int main(void) {
    printf("%.0f %.0f\n", cbrt(-125.0), cbrt(27.0));
    return 0;
}

Result

-5 3

Use it instead of `pow(x, 1.0/3.0)`, especially for negative numbers. The example genuinely computes `cbrt(-125.0) = -5` and `cbrt(27.0) = 3`, then prints both results.

Sources