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

noreply@sourceforge.net noreply@sourceforge.net
Tue, 19 Nov 2002 17:55:12 -0800


Bugs item #640554, was opened at 2002-11-19 03: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: Tim Peters (tim_one)
Date: 2002-11-19 20: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