Floating-point glitches with the math module. Bug? Or am Imissing something?

Alex Martelli aleaxit at yahoo.com
Wed Sep 22 07:38:45 EDT 2004


Terry Reedy <tjreedy at udel.edu> wrote:
   ...
> > derivative of f at a is 0.  Therefore f(a+h) ~= f(a) + h**2*f''(a)/2
> > (the first-order term of the Taylor expansion around a vanishes).
> > That in turn roughly means that if you change any of the bits in the
> > least significant half of a, it makes no visible difference to the
> > computed value of f(a).
> 
> To illustrate:
> >>> for i in range(50): print `cos(i*1e-9)` # Windows, 2.2

FWIW, these are exactly identical to the results I get from IBM's
Accurate Portable Mathematical Library (APMathLib), claimed to equal
"the exact theoretical values correctly rounded (nearest or even) to the
closest number representable by the IEEE 754 double format" (in other
words, correct to the Unit of Least Precision, ULP).  So, for once, it's
apparently not the fault of the underlying C mathematical library.


Alex



More information about the Python-list mailing list