Conversion, rounding, and truncation
David Hough
dgh at sun.uucp
Thu Nov 6 05:44:09 AEST 1986
> pow(x,y) is basically implemented as exp(y*log(x)),
> with domain and range checking too of course.
> Depending on the exact implemen-
> tation of exp() and log(), this can give results which are slightly off even
> when an exact solution would be representable. As a
> guru explained to me, this is done, even if it would be possible to special-
> case exactly-integral exponents to pow(), in order to preserve the local
> continuity of the function.
It is true that the simplest way to implement pow(x,y) is exp(y*log(x)).
That is not the best way. There is no inherent reason why x**y for
small integer values x and y
can not be computed correctly and without losing monotonicity.
The pow() in recent Sun software releases
and in 4.3 BSD works pretty well. In contrast most Unix implementations
of libm functions are pretty poor - Gene Spafford (gatech!spaf) wrote a book
about them.
The paranoia program distributed by Richard Karpinski
(ucbvax!ucsfcgl!cca.ucsf!dick) tests computer arithmetic, including
pow() at small integer values.
David Hough dhough at sun.com
More information about the Comp.lang.c
mailing list