[Python-bugs-list] [ python-Bugs-496104 ] FP behaviour changed from 2.1.1

noreply@sourceforge.net noreply@sourceforge.net
Sat, 22 Dec 2001 08:35:52 -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: Tim Peters (tim_one)
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: 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