[Numpy-discussion] math.exp underflow (was: exp behaviour: is it a bug ?)

Charles G Waldman cgw at fnal.gov
Fri Jun 2 11:36:55 CDT 2000


Czerminski, Ryszard writes:
 > 
 > Is the behaviour illustrated below a bug or the Python's feature ?

I don't know why you're posting this to the NumPy discussion list,
since the
"math" module is part of the standard Python distribution, not NumPy.

Anyhow, the differing behaviors people are seeing are just coming from
differences in the system math libraries:

On Linux (Intel):

Python 1.6a2 (#9, May 22 2000, 12:34:51)  [GCC 2.95.2 19991024 (release)] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
Copyright 1995-2000 Corporation for National Research Initiatives (CNRI)
>>> from math import exp
>>> x = -706.
>>> while x > -900:
...    x = x - 1
...    print 'x, exp(x) = %g %g' % (x, exp(x))
... 
x, exp(x) = -707 8.99086e-308
x, exp(x) = -708 3.30755e-308
<snip>
x, exp(x) = -745 4.94066e-324
x, exp(x) = -746 0
<snip>
x, exp(x) = -899 0
x, exp(x) = -900 0
>>> 


Wheras on Irix (MIPS):
Python 1.6a2 (#8, Jun  1 2000, 20:01:55) [C] on irix646
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
Copyright 1995-2000 Corporation for National Research Initiatives (CNRI)
>>> from math import exp
>>> x = -706.
>>> while x > -900:
...    x = x - 1
...    print 'x, exp(x) = %g %g' % (x, exp(x))
... 
x, exp(x) = -707 8.99086e-308
x, exp(x) = -708 3.30755e-308
x, exp(x) = -709 0
x, exp(x) = -710 0
<snip>
x, exp(x) = -745 0
Traceback (most recent call last):
  File "<stdin>", line 3, in ?
OverflowError: math range error




More information about the Numpy-discussion mailing list