numpy, overflow, inf, ieee, and rich comparison

Tim Roberts timr at probo.com
Mon Oct 9 23:49:39 EDT 2000


hzhu at users.sourceforge.net (Huaiyu Zhu) wrote:

>I'm stumbling over a seemingly trivial problem.  Following are some
>descriptions of the problem, various attemps at solving it, and some
>comments. 
>
>We know that exp(-1000) is approximately zero to machine precision.
>However, on my machine
>
>>>> from math import *
>>>> exp(-745)
>4.9406564584124654e-324
>>>> exp(-746)
>Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
>OverflowError: math range error

Hmmm.  My Win98 box with Python 2.0b2 gives very different results:

>>> exp(-740)
4.150151425066471e-322
>>> exp(-744)
4.9406564584124654e-324
>>> exp(-745)
0.0
>>> exp(-746)
0.0
>>> exp(-800)
0.0

Interestoid #1 is that I don't get a range error; I assume something was
fixed in 2.0.  Interestoid #2 is that my exp(-744) == your exp(-745).  I
can't see that either result is correct; both my Casio calculator (using
logarithms) and trusty old "bc", exp(-744) should be about 7.67e-324.

I assume we've reached the lower limit of an IEEE 64-bit float?

Interestoid #3 is that the results are different on the positive side:

>>> for k in range(700,740,1):
...   print k, exp(k)
...
700 1.01423205474e+304
701 2.75696856423e+304
702 7.49421754977e+304
703 2.03713953841e+305
704 5.53751938928e+305
705 1.50525383306e+306
706 4.09170414163e+306
707 1.11224050156e+307
708 3.02338314428e+307
709 8.21840746155e+307
710
Traceback (most recent call last):
  File "<stdin>", line 2, in ?
OverflowError: math range error

--
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list