]> granicus.if.org Git - python/commitdiff
Bug #1481296: Fixed long(float('nan'))!=0L.
authorChristian Heimes <christian@cheimes.de>
Fri, 4 Jan 2008 00:37:34 +0000 (00:37 +0000)
committerChristian Heimes <christian@cheimes.de>
Fri, 4 Jan 2008 00:37:34 +0000 (00:37 +0000)
Lib/test/test_long.py
Misc/NEWS
Objects/longobject.c

index 29515c7bb70c576e5fcba8ad9ea58f357b56eb58..d74535040a47bcdd2fa2878c03328f3e353edd58 100644 (file)
@@ -498,6 +498,10 @@ class LongTest(unittest.TestCase):
                 eq(x > y, Rcmp > 0, Frm("%r > %r %d", x, y, Rcmp))
                 eq(x >= y, Rcmp >= 0, Frm("%r >= %r %d", x, y, Rcmp))
 
+    def test_nan_inf(self):
+        self.assertRaises(OverflowError, long, float('inf'))
+        self.assertEqual(long(float('nan')), 0L)
+
 def test_main():
     test_support.run_unittest(LongTest)
 
index 87de1235bee36d06630032765083b6a789ca5677..bd98e38fb2cf3a3ac861ce6b72ccb3a864c21cf9 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 2.6 alpha 1?
 Core and builtins
 -----------------
 
+- Bug #1481296: Fixed long(float('nan'))!=0L.
+
 - Issue #1640: Added math.isinf(x), math.isnan(x) and math.copysign(x, y)
   functions.
 
index 262b40ade123cecee4e9047f55a4b25d85ed1c53..e2ffb35a9747fbaad81ef9cca519ebcf1f86ce41 100644 (file)
@@ -170,6 +170,9 @@ PyLong_FromDouble(double dval)
                        "cannot convert float infinity to long");
                return NULL;
        }
+       if (Py_IS_NAN(dval)) {
+               return PyLong_FromLong(0L);
+       }
        if (dval < 0.0) {
                neg = 1;
                dval = -dval;