Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!ucla-cs!ucla-ma!euphemia!pmontgom From: pmontgom@euphemia.math.ucla.edu (Peter Montgomery) Newsgroups: comp.arch Subject: Re: float/float = integer, remainder Message-ID: <1991May13.052859.18951@math.ucla.edu> Date: 13 May 91 05:28:59 GMT References: <9105130317.AA09926@ucbvax.Berkeley.EDU> Sender: news@math.ucla.edu Organization: UCLA Mathematics Dept. Lines: 49 In article <9105130317.AA09926@ucbvax.Berkeley.EDU> jbs@WATSON.IBM.COM writes: > > Herman Rubin states: > I have already pointed out >that every trigonometric and exponential routine does, in some way, >float/float -> integer, remainder. The integer is also used. > > 1. As I have already pointed out, the actual computation being >done is float/real -> integer, remainder (since pi and ln(2) are not ma- >chine numbers). A proposed float/float -> integer, remainder instruc- >tion (assuming it ran at the same speed as floating divide, actually it >would probably be slower) would not benefit the trigonometric or >exponential routines on any architecture I am familiar with Suppose we want sin(1234.0). Approximate pi/2 = pi1 + pi2 where pi1 and pi2 are each double precision, | pi1 | >> | pi2 |. For purposes of illustration, let pi1 = 1.571 pi2 = - .0002037 (decimal notation with four significant digits) so that pi1 + pi2 = 1.5707963 whereas pi/2 = 1.57079632679 ... . Herman's proposed instruction would find 1234.0 = 785*pi1 + 0.765 . If the quotient is always rounded to the nearest integer, then the remainder (here 0.765) can be represented exactly even though 785*1.571 = 1233.235 requires more that four significant digits. How can Herman Rubin get this remainder accurately with the hardware and software commonly available? jbs argues that this remainder 0.765 is only an approximation to 1234.0 mod pi/2, since the divisor 3.142 was an approximation. This is where pi2 can be used, together with the first quotient and remainder: 1234.0 - 785*(pi1 + pi2) = (1234.0 - 785*pi1) - 785*pi2 = 0.7650 + 785*.0002037 = 0.7650 + .1599045 = 0.9249 (using 4-digit arithmetic). The revised remainder of 0.9249 compares to the true value 0.9248834 of 1234 - 785*(pi/2). With this we estimate sin(1234) ~= cos(0.9249) ~ 0.6019, which is accurate to four digits. -- Peter L. Montgomery pmontgom@MATH.UCLA.EDU Department of Mathematics, UCLA, Los Angeles, CA 90024-1555 If I spent as much time on my dissertation as I do reading news, I'd graduate.