Kaydet (Commit) a4e0efa4 authored tarafından Mark Dickinson's avatar Mark Dickinson

Issue #5829: don't raise OverflowError for complex('1e500'). Backport of r72803.

üst ac2380b5
...@@ -429,6 +429,13 @@ class ComplexTest(unittest.TestCase): ...@@ -429,6 +429,13 @@ class ComplexTest(unittest.TestCase):
self.assertEquals(atan2(z1.imag, -1.), atan2(0., -1.)) self.assertEquals(atan2(z1.imag, -1.), atan2(0., -1.))
self.assertEquals(atan2(z2.imag, -1.), atan2(-0., -1.)) self.assertEquals(atan2(z2.imag, -1.), atan2(-0., -1.))
@unittest.skipUnless(float.__getformat__("double").startswith("IEEE"),
"test requires IEEE 754 doubles")
def test_overflow(self):
self.assertEqual(complex("1e500"), complex(INF, 0.0))
self.assertEqual(complex("-1e500j"), complex(0.0, -INF))
self.assertEqual(complex("-1e500+1.8e308j"), complex(-INF, INF))
@unittest.skipUnless(float.__getformat__("double").startswith("IEEE"), @unittest.skipUnless(float.__getformat__("double").startswith("IEEE"),
"test requires IEEE 754 doubles") "test requires IEEE 754 doubles")
def test_repr_roundtrip(self): def test_repr_roundtrip(self):
......
...@@ -12,6 +12,10 @@ What's New in Python 2.7 alpha 1 ...@@ -12,6 +12,10 @@ What's New in Python 2.7 alpha 1
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #5829: complex("1e500") no longer raises OverflowError. This
makes it consistent with float("1e500") and interpretation of real
and imaginary literals.
- Issue #3527: Removed Py_WIN_WIDE_FILENAMES which is not used any more. - Issue #3527: Removed Py_WIN_WIDE_FILENAMES which is not used any more.
- __instancecheck__ and __subclasscheck__ are now completely ignored on classic - __instancecheck__ and __subclasscheck__ are now completely ignored on classic
......
...@@ -989,8 +989,6 @@ complex_subtype_from_string(PyTypeObject *type, PyObject *v) ...@@ -989,8 +989,6 @@ complex_subtype_from_string(PyTypeObject *type, PyObject *v)
z = PyOS_ascii_strtod(s, &end); z = PyOS_ascii_strtod(s, &end);
if (end == s && errno == ENOMEM) if (end == s && errno == ENOMEM)
return PyErr_NoMemory(); return PyErr_NoMemory();
if (errno == ERANGE && fabs(z) >= 1.0)
goto overflow;
if (end != s) { if (end != s) {
/* all 4 forms starting with <float> land here */ /* all 4 forms starting with <float> land here */
...@@ -1002,8 +1000,6 @@ complex_subtype_from_string(PyTypeObject *type, PyObject *v) ...@@ -1002,8 +1000,6 @@ complex_subtype_from_string(PyTypeObject *type, PyObject *v)
y = PyOS_ascii_strtod(s, &end); y = PyOS_ascii_strtod(s, &end);
if (end == s && errno == ENOMEM) if (end == s && errno == ENOMEM)
return PyErr_NoMemory(); return PyErr_NoMemory();
if (errno == ERANGE && fabs(y) >= 1.0)
goto overflow;
if (end != s) if (end != s)
/* <float><signed-float>j */ /* <float><signed-float>j */
s = end; s = end;
...@@ -1063,11 +1059,6 @@ complex_subtype_from_string(PyTypeObject *type, PyObject *v) ...@@ -1063,11 +1059,6 @@ complex_subtype_from_string(PyTypeObject *type, PyObject *v)
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
"complex() arg is a malformed string"); "complex() arg is a malformed string");
return NULL; return NULL;
overflow:
PyErr_SetString(PyExc_OverflowError,
"complex() arg overflow");
return NULL;
} }
static PyObject * static PyObject *
......
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