numpy, overflow, inf, ieee, and rich comparison

Tim Peters tim_one at email.msn.com
Tue Oct 10 07:01:40 EDT 2000


[Huaiyu Zhu]
> ...
> I thought so, BUT
>
> $ /usr/bin/python
> Python 1.5.2 (#1, Sep 17 1999, 20:15:36)  [GCC egcs-2.91.66 19990314/Linux
> (egcs- on linux-i386
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> from math import *
> >>> exp(-745)
> 4.94065645841e-324
> >>> exp(-746)
> 0.0
>
> $ /usr/local/bin/python
> Python 2.0b2 (#2, Oct  6 2000, 17:54:55)
> [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
> Type "copyright", "credits" or "license" for more information.
> >>> from math import *
> >>> exp(-745)
> 4.9406564584124654e-324
> >>> exp(-746)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> OverflowError: math range error
>
> This is on the same machine. Notice that GCC?  Exactly the same
> version.

I'm not enough of a collector of gcc trivia to see at once that egcs-2.91.66
is exactly the same as egcs-1.1.2, but if you say so ...

> So what's going on here?

Can't answer your question.  It's a platform-dependent crap shoot, and in
any case is usually entirely due to the libraries you're linking with and
nothing to do with the compiler.  Do you have any way to tell which
libraries you're using in the two cases?  Can you still get at them?  If so,
write a little C program to do the same thing, and see whether exp sets
errno there.

> I was wondering why I hadn't noticed this underflow for such a
> long time ...
>
> Maybe 2.0 fixes Window's bug wile introducing Linux bug? One thing I can
> confirm is that Numeric behaves the same as math in this regard.

The CVS history of mathmodule.c is available online, at (sorry, but this
line will get broken -- paste back together on your end):

    http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/python/dist/src/
    Modules/mathmodule.c?cvsroot=python

>From that, you can see that math_1 has been raising an error on non-zero
errno since Sun Oct 14 12:07:23 1990 (i.e., since the beginning of RPT
(Recorded Python Time)).  The 1.5.2 version is revision 2.42.  Nothing
interesting about Python's math.exp has changed since then on any platform.

when-you're-tracking-down-accidents-don't-look-so-hard-
     for-sense<0.7-wink>-ly y'rs  - tim






More information about the Python-list mailing list