How not to write a loop, revisited

Herman Rubin cik at l.cc.purdue.edu
Sat Jun 25 21:35:31 AEST 1988


In article <12784 at apple.Apple.COM>, bgibbons at Apple.COM (Bill Gibbons) writes:
> >>I believe that floating point arithmetic is exact as long as all the values
> >>are integers with not too many bits ....
> >>...
  
		--------------------------------------------

> I agree that exponentiation is not safe, but raising a floating-point value to
> an integer (typed as integer) power is always done with repeated multiplies
> (in about log2(exponent) time), and since multiplies are accurate, so is this
> type of exponentiation.

		---------------------------------------------

Apparently Bill missed the discussion a few months ago about exponentiation
in C.  There was considerable disagreement about what should be done about
the problem, and a rather large number of correspondents seemed unable to
consider computing powers except by the pow(x,y) function, which does not
use the reasonably quick and exact method.  

There seems to be a considerable lack of understanding of the need for good
integer arithmetic for mathematical computations.  This shows up in both
hardware and software.  If one looks at Brent's multiple precision package,
one sees that it is necessary to go to short words to handle the problem.
It is easy to simulate floating point with integer arithmetic, but clumsy
and slow the other way around.
-- 
Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907
Phone: (317)494-6054
hrubin at l.cc.purdue.edu (ARPA or UUCP) or hrubin at purccvm.bitnet



More information about the Comp.lang.c mailing list