In real world cube root for a negative number should exist:
cuberoot(-1)=-1, that means (-1)*(-1)*(-1)=-1
or
cuberoot(-27)=-3, that means (-3)*(-3)*(-3)=-27
But when I calculate cube root of a negative number in C using pow function, I get nan (not a number)
double cuber;
cuber=pow((-27.),(1./3.));
printf("cuber=%f\n",cuber);
output: cuber=nan
Is there any way to calculate cube root of a negative number in C?
7.12.7.1 The
cbrtfunctionsSynopsis
Description
The
cbrtfunctions compute the real cube root ofx.If you’re curious,
powcan’t be used to compute cube roots because one-third is not expressible as a floating-point number. You’re actually askingpowto raise-27.0to a rational power very nearly equal to 1/3; there is no real result that would be appropriate.