C++ cmath cbrt , cbrtf and cbrtl function

The C++ <cmath> 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);

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

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

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

/*Passing floating point value*/
cout<< “cbrt(3)=” << cbrt(3) << endl;

/*Passing -ve value*/
cout<< “cbrt(9)=” << cbrt(-9) << endl;

/*Passing NAN */
cout<< “cbrt(NAN)=” << cbrt(NAN) << endl;

/*Passing INFINITY*/
cout<< “cbrt(-INFINITY)=” << cbrt(-INFINITY) << endl;


cbrt(3)= 1.44225
cbrt(-9)= -2.08008
cbrt(NAN)= nan
cbrt(-INFINITY)= -inf


cbrtf and cbrtl


i)The 4th version cbrtf is same as the 1st version float cbrt(float) .The ‘f‘ character appended to ‘cbrtf’ stands for ‘float’ which signify the argument type and return type of the function.

ii)The 5th version cbrtl is same as the 3rd version long double cbrt(long double).The ‘l‘ character in ‘cbrtl’ stands for ‘long double’ which signify the argument type and return type of the function.

Code example

#include <typeinfo>

/*cbrtf */
cout<< “*cbrtf\n”;
float f=2;
cout<< typeid( cbrtf(2) ).name() << endl /*identify type of cbrtf retunred value */
<< typeid( cbrt(f) ).name() << endl; /*identify type of cbrt(float) returned value */

cout<< “*cbrtl\n”;
long double ld=2;
cout<< typeid( cbrtl(2) ).name() << endl /*indentify type of cbrtl returned value */
<< typeid( cbrt(ld) ).name() << endl; /*identify type of cbrt(long double) returned value*/


e (means ‘long double’)
e (means ‘long double’)

The return type of cbrt(float) and ‘cbrtf’ is same,similarly the return type of cbrt(long double) and ‘cbrtl’ is same.