C programming cbrt , cbrtf and cbrtl math.h


In C programming the <math.h> cbrt,cbrtf and cbrtl compute the real cube root of the value.The declaration of the functions are given below.

1 float cbrt(float x);
2 double cbrt(double x);
3 long double cbrt(long double x);
4 float cbrtf(float x);
5 long double cbrtl(long double x);

Parameters:
x -A floating point value whose cube root is to be computed.

Return type
floating point-The cube root of ‘x’.

All the functions are the same,they compute the real cube root of the argument value.The 1st,2nd and the 3rd function have the same name i.e.’cbrt’.The 4th and 5th function have different names.What does having a different names mean is explained in detail below.

Some points to note:

i) cbrt(x) is same as x1/3.

ii) If NAN is passed ‘nan’ is returned.

ii) If ±∞ is passed ±∞ is returned.

Code example

double d=12 , x1=200 ;

float f=12 ;

long double ld=12 ;

printf(“%lf”, cbrt( d ) ) ; //calls the 2nd version
printf(“\n%f”, cbrtf( f ) ) ; //calls the 1st version
printf(“\n%Lf”, cbrtl( ld ) ) ;//calls the 3rd version

printf(“\n%lf”, cbrt( x1 ) ) ;
printf(“\n%lf”, cbrt( NAN ) ) ;

Output in Visual Studio,

2.289428
2.289428
2.289428
5.848035
-nan(ind)

If ‘NAN’ is passed as argument ‘-nan(ind)'(it simply means ‘NaN’).

Link:C++ nan






cbrtf

The ‘cbrtf‘ function is same as the 1st function.This means the parameter and return type of the function is float type.The ‘f‘ character appended to ‘cbrtf‘ stands for float and it signify the parameter type and return type of the function.

Code example

float x=27000 ;

printf(“%f”, cbrt( x ) ); //Calls the 1st version
printf(“\n%f”, cbrtf( 27000 ) ); Calls the 4th version

Output in Visual Studio,

30.000000
30.000000


cbrtl

The ‘cbrtl‘ function is same as the 1st function.This means the parameter and return type of the function is long double type.The ‘l‘ character appended to ‘cbrtl‘ stands for long double and it signify the parameter type and return type of the function.

Code example

long double x=27000 ;

printf(“%Lf”, cbrt( x ) ); //Calls the 3rd version
printf(“\n%Lf”, cbrtl( 27000 ) ); Calls the 5th version

Output,

30.000000
30.000000