Commit 0e701695 authored by Christian Heimes's avatar Christian Heimes

long(float('nan')) raises an OverflowError as discussed on the mailing list a week ago

parent 02c10eb1
...@@ -539,7 +539,7 @@ class LongTest(unittest.TestCase): ...@@ -539,7 +539,7 @@ class LongTest(unittest.TestCase):
def test_nan_inf(self): def test_nan_inf(self):
self.assertRaises(OverflowError, int, float('inf')) self.assertRaises(OverflowError, int, float('inf'))
self.assertEqual(int(float('nan')), 0) self.assertRaises(OverflowError, int, float('nan'))
def test_main(): def test_main():
test_support.run_unittest(LongTest) test_support.run_unittest(LongTest)
......
...@@ -12,6 +12,9 @@ What's New in Python 3.0a3? ...@@ -12,6 +12,9 @@ What's New in Python 3.0a3?
Core and Builtins 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 - Issue #1762972: __file__ points to the source file instead of the pyc/pyo
file if the py file exists. file if the py file exists.
......
...@@ -255,7 +255,9 @@ PyLong_FromDouble(double dval) ...@@ -255,7 +255,9 @@ PyLong_FromDouble(double dval)
return NULL; return NULL;
} }
if (Py_IS_NAN(dval)) { 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) { if (dval < 0.0) {
neg = 1; neg = 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment