[Python-bugs-list] [ python-Bugs-496104 ] FP behaviour changed from 2.1.1
noreply@sourceforge.net
noreply@sourceforge.net
Mon, 24 Dec 2001 17:04:58 -0800
Bugs item #496104, was opened at 2001-12-22 06:33
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=496104&group_id=5470
Category: Python Interpreter Core
Group: Python 2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Andreas Dietrich (quasi)
Assigned to: Guido van Rossum (gvanrossum)
Summary: FP behaviour changed from 2.1.1
Initial Comment:
Python2.2 floating point behaviour
is different from 2.1.1 on Linux.
Instead of Inf and nan an OverflowError is
raised. (sometimes):
Python 2.2 (#5, Dec 22 2001, 14:57:12)
[GCC 2.96 20000731 (Mandrake Linux 8.2 2.96-0.68mdk)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> 1e308**10
Traceback (most recent call last):
File "<stdin>", line 1, in ?
OverflowError: (34, 'Numerical result out of range')
>>> math.tan(1e308**10)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
OverflowError: (34, 'Numerical result out of range')
>>> 1e308*10
inf
>>> math.tan(1e308*10)
nan
Python 2.1.1 (#1, Oct 24 2001, 13:07:11)
[GCC 2.96 20000731 (Mandrake Linux 8.2 2.96-0.66mdk)] on linux-i386
Type "copyright", "credits" or "license" for more information.
>>> import math
>>> 1e308**10
inf
>>> math.tan(1e308**10)
nan
>>> 1e308*10
inf
>>> math.tan(1e308*10)
nan
----------------------------------------------------------------------
>Comment By: Guido van Rossum (gvanrossum)
Date: 2001-12-24 17:04
Message:
Logged In: YES
user_id=6380
Anthony is channeling me correctly.
----------------------------------------------------------------------
Comment By: Anthony Baxter (anthonybaxter)
Date: 2001-12-24 16:47
Message:
Logged In: YES
user_id=29957
I'm not Guido, but on RH7.1 here:
>>> import math
>>> x = 1e308
>>> x ** 10
Traceback (most recent call last):
File "<stdin>", line 1, in ?
OverflowError: (34, 'Numerical result out of range')
>>> x ** 9.99
Traceback (most recent call last):
File "<stdin>", line 1, in ?
OverflowError: (34, 'Numerical result out of range')
>>> pow(x, 10)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
OverflowError: (34, 'Numerical result out of range')
>>>
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2001-12-24 15:38
Message:
Logged In: YES
user_id=31435
Guido, can you try this on Linux under 2.2?
"""
import math
x = 1e308
x ** 10
x ** 9.99
pow(x, 10)
"""
Assign the bug back to me regardless. If the last three
lines all raise OverflowError on Linux, I intend to close
the bug (as WontFix). But if one or more of those doesn't
raise OverflowError, my rationale sucks so I'd need to
think harder.
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2001-12-22 08:35
Message:
Logged In: YES
user_id=31435
Python doesn't define what happens in such cases, and it
varied across platforms (depending on vagaries of the
platform C compiler and libraries). It should be more
consistent in 2.2 than in 2.1. For example, under 2.1
(Windows here):
C:\Python21>python
Python 2.1.1 (#20, Jul 20 2001, 01:19:29) [MSC 32 bit
(Intel)] on win32
Type "copyright", "credits" or "license" for more
information.
>>> x = 1e308
>>> x ** 10 # as you saw on Linux
1.#INF
>>> x ** 9.99 # but a smaller exponent as a float blows up
Traceback (most recent call last):
File "<stdin>", line 1, in ?
OverflowError: (34, 'Result too large')
>>> import math
>>> math.pow(x, 10) # ditto spelling it pow() instead of **
Traceback (most recent call last):
File "<stdin>", line 1, in ?
OverflowError: math range error
>>>
Under 2.2, though, they're all OverflowErrors:
C:\Python22>python
Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more
information.
>>> x = 1e308
>>> x ** 10
Traceback (most recent call last):
File "<stdin>", line 1, in ?
OverflowError: (34, 'Result too large')
>>> x ** 9.9
Traceback (most recent call last):
File "<stdin>", line 1, in ?
OverflowError: (34, 'Result too large')
>>> import math
>>> math.pow(x, 10)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
OverflowError: math range error
>>>
If the results in all 3 cases are OverflowError on Linux
too in 2.2, I have to count that as an improvement (but
regretting that it changed -- Python's fp behavior is often
accidental, and making it more predictable is difficult for
implementers and frustrating for users).
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=496104&group_id=5470