[Python-bugs-list] [ python-Bugs-640554 ] Overflow in Objects/floatobject.c

noreply@sourceforge.net noreply@sourceforge.net
Wed, 20 Nov 2002 15:23:04 -0800


Bugs item #640554, was opened at 2002-11-19 08:06
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=640554&group_id=5470

Category: Python Interpreter Core
Group: Python 2.2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Nick Maclaren (nmm1)
Assigned to: Nobody/Anonymous (nobody)
Summary: Overflow in Objects/floatobject.c

Initial Comment:
Objects/floatobject.c has a bug on systems where
converting a double
into a long but where it doesn't fit causes a trap. 
The following
fix is generic:

*** Objects/floatobject.c.org   Sun May 12 18:20:38
2002
--- Objects/floatobject.c       Mon Nov 18 20:20:28
2002
***************
*** 656,662 ****
           to long may yield gibberish in either case. 
What really matters
           is whether converting back to double again
reproduces what we
           started with. */
!       aslong = (long)wholepart;
        if ((double)aslong == wholepart)
                return PyInt_FromLong(aslong);
        PyErr_SetString(PyExc_OverflowError, "float too
large to convert");
--- 656,664 ----
           to long may yield gibberish in either case. 
What really matters
           is whether converting back to double again
reproduces what we
           started with. */
!         aslong = (wholepart >= LONG_MIN && wholepart
<= LONG_MAX ?
!             (long)wholepart :
!             0);
        if ((double)aslong == wholepart)
                return PyInt_FromLong(aslong);
        PyErr_SetString(PyExc_OverflowError, "float too
large to convert");


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

>Comment By: Nick Maclaren (nmm1)
Date: 2002-11-20 23:23

Message:
Logged In: YES 
user_id=652073

Solaris with -fptrap=common.  What I am setting as the
default on our systems (and shall see how many people
screech).  It was also possible in Norcroft C on Phoenix
(all right, that IS obscure) and I have been told that it
is fairly widespread (though not the norm) in embedded
compilers.  There are others, though it is rarely the
default.

You may gather how long I have been in this game when I say
that I remember when a large number of systems trapped
integer overflow by default :-)  I still have the very
old-fashioned view that a clean failure is better than
wrong answers ....


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

Comment By: Tim Peters (tim_one)
Date: 2002-11-20 01:55

Message:
Logged In: YES 
user_id=31435

I'm curious:  which system do you have in mind?  I 
understand that it's possible, and agree with your 
proposed fix.  I've simply never bumped into a system that 
did a raise a trap,

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

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