[Python-checkins] r59689 - in python/trunk: Lib/test/test_long.py Misc/NEWS Objects/longobject.c

christian.heimes python-checkins at python.org
Fri Jan 4 01:37:35 CET 2008


Author: christian.heimes
Date: Fri Jan  4 01:37:34 2008
New Revision: 59689

Modified:
   python/trunk/Lib/test/test_long.py
   python/trunk/Misc/NEWS
   python/trunk/Objects/longobject.c
Log:
Bug #1481296: Fixed long(float('nan'))!=0L.

Modified: python/trunk/Lib/test/test_long.py
==============================================================================
--- python/trunk/Lib/test/test_long.py	(original)
+++ python/trunk/Lib/test/test_long.py	Fri Jan  4 01:37:34 2008
@@ -498,6 +498,10 @@
                 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)
 

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Fri Jan  4 01:37:34 2008
@@ -12,6 +12,8 @@
 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.
 

Modified: python/trunk/Objects/longobject.c
==============================================================================
--- python/trunk/Objects/longobject.c	(original)
+++ python/trunk/Objects/longobject.c	Fri Jan  4 01:37:34 2008
@@ -170,6 +170,9 @@
 			"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;


More information about the Python-checkins mailing list