pow()
Richard A. O'Keefe
ok at quintus
Mon Jul 11 11:26:36 AEST 1988
I have received e-mail taking me to task for claiming that pow() in C is
similar to ** in Fortran. My correspondent was apparently labouring under
the impression that pow(x,y) was the equivalent only of REAL(x)**REAL(y).
The System V Interface Definition explicitly states that pow(x, y) is
valid for negative x provided that "y is an integer". Judging by the
versions I have used, pow() behaves *as if* it did
if there is an integer n such that (double)n == y
return x**n /* e.g. pow(-2.0, 3.0) = (-2.0)**3 = -8.0 */
else
return exp(log(x)*y);
While I personally think this is an ugly hack and that it would have been
better to have two functions, this does seem to be the way things are in UNIX.
The question is: what does the dpANS say? Is this special-casing for
exponents which happen to approximate integers required, forbidden, allowed?
More information about the Comp.lang.c
mailing list