]> granicus.if.org Git - python/commitdiff
long(float('nan')) raises an OverflowError as discussed on the mailing list a week ago
authorChristian Heimes <christian@cheimes.de>
Tue, 15 Jan 2008 02:01:20 +0000 (02:01 +0000)
committerChristian Heimes <christian@cheimes.de>
Tue, 15 Jan 2008 02:01:20 +0000 (02:01 +0000)
Lib/test/test_long.py
Misc/NEWS
Objects/longobject.c

index 09adc74991875c5f4ceaa8075110c2814205af1a..18bb7a4595654b5473d578e825457a9b089585b0 100644 (file)
@@ -539,7 +539,7 @@ class LongTest(unittest.TestCase):
 
     def test_nan_inf(self):
         self.assertRaises(OverflowError, int, float('inf'))
-        self.assertEqual(int(float('nan')), 0)
+        self.assertRaises(OverflowError, int, float('nan'))
 
 def test_main():
     test_support.run_unittest(LongTest)
index 8a770609bacf2db7e2aa0de20e2de6f03e77d23d..c59efa1b435bb977662fd395f8693f1ffd152d18 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 3.0a3?
 Core and Builtins
 -----------------
 
+- Object/longobject.c: long(float('nan')) raises an OverflowError instead
+  of returning 0.
+
 - Issue #1762972: __file__ points to the source file instead of the pyc/pyo
   file if the py file exists.
 
index dc7ce87afceb25e07682475938db7fc4fa4e1631..4b7eee059cd7ea4198fa3492069835242589e39b 100644 (file)
@@ -255,7 +255,9 @@ PyLong_FromDouble(double dval)
                return NULL;
        }
        if (Py_IS_NAN(dval)) {
-               return PyLong_FromLong(0L);
+               PyErr_SetString(PyExc_OverflowError,
+                       "cannot convert float NaN to int");
+               return NULL;
        }
        if (dval < 0.0) {
                neg = 1;