math module broken?

Tim Peters tim.peters at gmail.com
Fri Jul 23 21:54:14 CEST 2004


[Christopher T King]
> ...
> Reduction... from 1.0e18?!  Of course that doesn't work with radians, it
> doesn't even works with degrees!

Actually, it can.  If you view a floating-point number as being
exactly what it says it is, then of course there's an exact reduction
of that number modulo pi.  Very high-quality math libraries compute
that too.  I know because I wrote one <wink>.  The popular fdlibm
(from Netlib) does "as-if infinite precision" trig argument reduction
too.  The details can be excruciating.  You (of course) need to know
pi to greater than machine precision, but not to as much greater as
you may think:  across all possible 754 doubles, you can find the one
closest to being an exact multiple of pi, and you only need to use
enough extra precision to get the right answer (to machine precision)
in that worst case.  At least 3 groups have discovered that
independently (I was one of them, discovered when writing a libm for
Kendall Square Research in the early 90's, in collaboration with Peter
Tang).

IIRC, Mary Payne at DEC was the first to implement "infinite
precision" trig argument reduction in a commercial math library, and
she wrote a very readable paper about it I'm unable to find now.  She
wasn't able to put an a priori bound on the amount of precision
needed, so it was less efficient than later attempts.

All in all, and despite having pushed the state of the art there
myself, it's a silly thng to bother with <wink>.



More information about the Python-list mailing list