cbrt, cbrtf, cbrtl - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# cbrt, cbrtf, cbrtl

From cppreference.com
< c‎ | numeric‎ | math

Defined in header `<math.h>` |  |
float cbrtf( float arg ); | (1) | (since C99)
double cbrt( double arg ); | (2) | (since C99)
long double cbrtl( long double arg ); | (3) | (since C99)
Defined in header `<tgmath.h>` |  |
#define cbrt( arg ) | (4) | (since C99)

1-3) Computes the cubic root of `arg`.
4) Type-generic macro: If `arg` has type long double, `cbrtl` is called. Otherwise, if `arg` has integer type or the type double, `cbrt` is called. Otherwise, `cbrtf` is called.

### [edit] Parameters

arg | - | floating point value

### [edit] Return value

If no errors occur, the cubic root of `arg` (3√arg), is returned.

If a range error occurs due to underflow, the correct result (after rounding) is returned.

### [edit] Error handling

Errors are reported as specified in math_errhandling.

If the implementation supports IEEE floating-point arithmetic (IEC 60559),

- if the argument is ±0 or ±∞, it is returned, unchanged
- if the argument is NaN, NaN is returned.

### [edit] Notes

cbrt(arg) is not equivalent to pow(arg, 1.0/3) because pow cannot raise a negative base to a fractional exponent.

### [edit] Example

Run this code

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

    int main(void)
    {
        // normal use
        printf("cbrt(729) = %f\n", cbrt(729));
        printf("cbrt(-0.125) = %f\n", cbrt(-0.125));
        // special values
        printf("cbrt(-0) = %f\n", cbrt(-0.0));
        printf("cbrt(+inf) = %f\n", cbrt(INFINITY));
    }

Output:

    cbrt(729) = 9.000000
    cbrt(-0.125) = -0.500000
    cbrt(-0) = -0.000000
    cbrt(+inf) = inf

### [edit] References

- C11 standard (ISO/IEC 9899:2011):

  - 7.12.7.1 The cbrt functions (p: 247)

  - 7.25 Type-generic math <tgmath.h> (p: 373-375)

  - F.10.4.1 The cbrt functions (p: 524)

- C99 standard (ISO/IEC 9899:1999):

  - 7.12.7.1 The cbrt functions (p: 228)

  - 7.22 Type-generic math <tgmath.h> (p: 335-337)

  - F.9.4.1 The cbrt functions (p: 460)

### [edit] See also

powpowfpowl (C99)(C99) | computes a number raised to the given power (xy) (function) [edit]
sqrtsqrtfsqrtl (C99)(C99) | computes square root (√x) (function) [edit]
hypothypotfhypotl (C99)(C99)(C99) | computes square root of the sum of the squares of two given numbers (√x2 +y2 ) (function) [edit]
C++ documentation for cbrt

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=c/numeric/math/cbrt&oldid=77330"