Namespaces
Variants
Views
Actions

cbrt

From cppreference.com
< c‎ | numeric‎ | math
 
 
 
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99)
(C99)
(C99)(C99)(C99)
Exponential functions
(C99)
(C99)
(C99)
(C99)
Power functions
cbrt
(C99)
(C99)
Trigonometric and hyperbolic functions
(C99)
(C99)
(C99)
Error and gamma functions
(C99)
(C99)
(C99)
(C99)
Nearest integer floating point operations
(C99)(C99)(C99)
(C99)
(C99)(C99)(C99)
Floating point manipulation functions
(C99)(C99)
(C99)
(C99)
Classification
(C99)
(C99)
(C99)
Macro constants
 
Defined in header <math.h>
float       cbrtf( float arg );
(since C99)
double      cbrt( double arg );
(since C99)
long double cbrtl( long double arg );
(since C99)

Computes cubic root of arg.

Contents

[edit] Parameters

arg - floating point value

[edit] Return value

Cubic root of arg.

[edit] Example

#include <stdio.h>
#include <math.h>
#include <errno.h>
#include <fenv.h>
#include <string.h>
 
#pragma STDC FENV_ACCESS ON
 
void show_fe_exceptions(void)
{
    printf("current exceptions raised: ");
    if(fetestexcept(FE_DIVBYZERO))     printf(" FE_DIVBYZERO");
    if(fetestexcept(FE_INEXACT))       printf(" FE_INEXACT");
    if(fetestexcept(FE_INVALID))       printf(" FE_INVALID");
    if(fetestexcept(FE_OVERFLOW))      printf(" FE_OVERFLOW");
    if(fetestexcept(FE_UNDERFLOW))     printf(" FE_UNDERFLOW");
    if(fetestexcept(FE_ALL_EXCEPT)==0) printf(" none");
    printf("\n");
}
 
int main(void)
{
    printf("cbrt(8.0)       = %.1f\n", cbrt(8.0));
    printf("pow(2.0,3.0)    = %.1f\n", pow(2.0,3.0));/* pow(x,3.0) is inverse of cbrt */
    printf("cbrt(+0.0)      = %.1f\n", cbrt(+0.0));
    printf("cbrt(-0.0)      = %.1f\n", cbrt(-0.0));
    printf("cbrt(+INFINITY) = %.1f\n", cbrt(+INFINITY));
    printf("cbrt(-INFINITY) = %.1f\n", cbrt(-INFINITY));
    printf("cbrt(NAN)       = %.1f\n", cbrt(NAN));
    printf("\n");
 
    /* "inexact" floating-point exception */
    errno = 0; feclearexcept(FE_ALL_EXCEPT);
    printf("cbrt(-1.0) = %.1f\n", cbrt(-1.0));
    printf("%s\n",strerror(errno));
    show_fe_exceptions();
 
    return 0;
}

Possible output:

cbrt(8.0)       = 2.0
pow(2.0,3.0)    = 8.0
cbrt(+0.0)      = 0.0
cbrt(-0.0)      = -0.0
cbrt(+INFINITY) = inf
cbrt(-INFINITY) = -inf
cbrt(+NAN)      = nan
 
cbrt(-1.0) = -1.0
Success
current exceptions raised:  FE_INEXACT

[edit] See also

computes square root (x)
(function) [edit]
raises a number to the given power (xy)
(function) [edit]