Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!pasteur!ucbvax!decwrl!purdue!i.cc.purdue.edu!k.cc.purdue.edu!l.cc.purdue.edu!cik From: cik@l.cc.purdue.edu (Herman Rubin) Newsgroups: comp.lang.c Subject: Re: How not to write a loop, revisited Summary: Exponentiation is not always done correctly Message-ID: <808@l.cc.purdue.edu> Date: 25 Jun 88 11:35:31 GMT References: <16276@brl-adm.ARPA> <329@accelerator.eng.ohio-state.edu> <12784@apple.Apple.COM> Organization: Purdue University Statistics Department Lines: 30 In article <12784@apple.Apple.COM>, bgibbons@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@l.cc.purdue.edu (ARPA or UUCP) or hrubin@purccvm.bitnet