J
John Smith
In a C program I need to do exponentiation where the base is
negative and the exponent is a fraction. In standard C this would
be something like t = pow(-11.5, .333), but with this combination
of arguments there is a domain error and the result is a
percolating NaN.
I worked around the problem by putting the standard function in a
wrapper:
double xpow(double b, double x)
{
double p;
if(b < 0)
{
p = pow(-b, x);
p *= -1.0;
}
else p = pow(b, x);
return p;
}
Is there any particular reason for this limitation in the
standard library function? Has anyone else had a problem with
this and found a better solution?
JS
negative and the exponent is a fraction. In standard C this would
be something like t = pow(-11.5, .333), but with this combination
of arguments there is a domain error and the result is a
percolating NaN.
I worked around the problem by putting the standard function in a
wrapper:
double xpow(double b, double x)
{
double p;
if(b < 0)
{
p = pow(-b, x);
p *= -1.0;
}
else p = pow(b, x);
return p;
}
Is there any particular reason for this limitation in the
standard library function? Has anyone else had a problem with
this and found a better solution?
JS