[Python-bugs-list] [ python-Bugs-525705 ] [2.2] underflow raise OverflowException

noreply@sourceforge.net noreply@sourceforge.net
Sat, 09 Mar 2002 17:20:12 -0800


Bugs item #525705, was opened at 2002-03-04 18:56
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=525705&group_id=5470

Category: Python Interpreter Core
Group: Platform-specific
>Status: Closed
>Resolution: Fixed
Priority: 7
Submitted By: Huaiyu Zhu (hzhu)
Assigned to: Tim Peters (tim_one)
Summary: [2.2] underflow raise OverflowException

Initial Comment:
Python 2.2 (#1, Mar  4 2002, 15:25:20) 
[GCC 2.95.2 19991024 (release)] on linux2
>>> 1e-200**2
OverflowError: (34, 'Numerical result out of range')

The machine runs SuSE 7.1. $ rpm -q gcc glibc
gcc-2.95.2-149
glibc-2.2-7

On this machine, the following test C program produces
1e+200   inf 34 Numerical result out of range 34
1e-200     0 34 Numerical result out of range 34
without -lieee, and 

1e+200   inf 0 Success 34
1e-200     0 0 Success 34
with -lieee.

However, editing pyconfig.h.in to add line
#define HAVE_LIBIEEE 1
does not change Python's behavior.

This problem does not occur on another machine, running
Red Hat 6.1 upgraded to 7.1.  It exhibits exactly the
same behavior regarding C, but Python underflows to 0.0
properly. 


The test C program is

#include <math.h>
#include <stdlib.h>
#include <errno.h>
extern int errno;

main() {
  double x;
  x = 1e200;
  printf("%g %5g %d %s %d\n", x, pow(x, 2), errno,
strerror(errno), ERANGE);
  x = 1e-200;
  printf("%g %5g %d %s %d\n", x, pow(x, 2), errno,
strerror(errno), ERANGE);
}


----------------------------------------------------------------------

>Comment By: Tim Peters (tim_one)
Date: 2002-03-09 20:20

Message:
Logged In: YES 
user_id=31435

Thanks, all!   That confirmed success on each kind of box 
originally complained about, and others I didn't know 
about.  Closing this now.

----------------------------------------------------------------------

Comment By: Nobody/Anonymous (nobody)
Date: 2002-03-09 14:18

Message:
Logged In: NO 

This problem was fixed in Python-20020309 for my box.  I am
running Debian Gnu Linux 2.2.19 ppc on a New World iMac.
The default configure did not add -lieee to LIBS and that
python did not give the underflow errors that python2.2
did.

----------------------------------------------------------------------

Comment By: Christopher Lee (clee)
Date: 2002-03-09 12:31

Message:
Logged In: YES 
user_id=1426

Tim Peter's fix in CVS looks good on my machine:

redhat 7.2, linux kernel 2.4.17, glibc 2.2.4-19.3, gcc 2.96-98

Python 2.3a0 (check out from cvs Sat Mar  9 11:26:31 CST 2002)

 ./python test_ieee.py 
x = 1e200
y = 1/x
check math.pow(x, 2): got math range error -OK
check math.pow(y, 2): got zero-OK
check pow(x, 2) got (34, 'Numerical result out of range') -OK
check pow(y, 2) got zero-OK
check x**2 got (34, 'Numerical result out of range') -OK
check y**2 got zero-OK

when running the following code
import math
x = 1e200
y = 1/x
print "x = 1e200"
print "y = 1/x"

try:
    print "check math.pow(x, 2):", 
    math.pow(x, 2)  # expect OverflowError
except  OverflowError, msg:
    print "got", msg, "-OK"


print "check math.pow(y, 2):", 
a=math.pow(y, 2)  # expect 0.
if a == 0.0:
    print "got zero-OK"
else:
    print "didn't get zero-FAIL"

try:
    print "check pow(x, 2)", 
    pow(x, 2)       # expect OverflowError
except  OverflowError, msg:
    print "got", msg, "-OK"

print "check pow(y, 2)", 
a=pow(y, 2)       # expect 0.
if a == 0.0: print "got zero-OK"

try:
    print "check x**2",
    x**2            # expect OverflowError
except  OverflowError, msg:
    print "got", msg, "-OK"

print "check y**2",
a=y**2            # expect 0.
if a==0.0:
    print "got zero-OK"





----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2002-03-09 10:24

Message:
Logged In: YES 
user_id=33168

RedHat 7.2, glibc-2.2.4-13

Before patch:
   w/o -lieee    w/-lieee
   FAILED        Passed

After patch:
   w/o -lieee    w/-lieee
   Passed        Passed

Works for me.
I also attached a modified script to what Tim posted on
python-dev which prints out if there is a problem.  Silence
is golden.

----------------------------------------------------------------------

Comment By: Andrew Dalke (dalke)
Date: 2002-03-09 02:52

Message:
Logged In: YES 
user_id=190903

Red Hat Linux release 6.2, with some updates.
Running on an Alpha box.  No changes to -ieee flag
(both compiled without -ieee)

Compared stock Python 2.2 vs. most recent CVS.

Using Python 2.2:
pow(1e-200, 2) and 1e-200**2 give OverflowError

Current CVS:
pow(1e-200, 2) and 1e-200**2 give 0.0


----------------------------------------------------------------------

Comment By: Jon Ribbens (jribbens)
Date: 2002-03-09 01:18

Message:
Logged In: YES 
user_id=76089

Python 2.2 on OpenBSD 2.7:
pow(1e-200, 2) and 1e-200**2 give OverflowError
Current CVS Python on OpenBSD 2.7:
pow(1e-200, 2) and 1e-200**2 give 0.0

I did not do anything with -lieee, just ./configure && make


----------------------------------------------------------------------

Comment By: Jeremy Hylton (jhylton)
Date: 2002-03-09 00:45

Message:
Logged In: YES 
user_id=31392

Tests work as expected on my Linux box (originally a RedHat 
6.2 system, with a bunch of upgrades, including glibc 
2.1).  The tests show the same results regardless of 
whether I link with -lieee.


----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2002-03-09 00:00

Message:
Logged In: YES 
user_id=31435

I'm hoping this is fixed in CVS now.  Since we're never 
going to sort out the Linux config mess, it tries to worm 
around it via more macros.

Include/pyport.h; new revision: 2.45
Modules/cmathmodule.c; new revision: 2.28
Objects/floatobject.c; new revision: 2.111

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2002-03-08 22:43

Message:
Logged In: YES 
user_id=31435

Python used to link with -lieee.  Rev 1.139 of configure.in 
changed that.  The checkin comment is:

"""
Gregor Hoffleit: Don't link with the libieee library if 
it's not necessary
"""

Thanks, Gregor <wink/sigh>.

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2002-03-08 22:40

Message:
Logged In: YES 
user_id=31435

Assigned to me, because the Linux weenies are apparently 
too frightened of radix points to get near this <wink>.

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2002-03-05 19:01

Message:
Logged In: YES 
user_id=31435

Changed Group to "Platform specific" and added "[2.2]" to 
the Summary line instead.

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2002-03-04 19:48

Message:
Logged In: YES 
user_id=31435

Boosted priority.  I'd assign to me, except I don't know 
anything about Linux config.

Paul Rubin reported success (no more bogus OverflowError) 
after

"""
I manually put "-lieee" into the LIBS=... line in the 
makefile and rebuilt.
"""

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=525705&group_id=5470