diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2009-05-20 18:41:04 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2009-05-20 18:41:04 (GMT) |
commit | 6b1e43b7bcbb85bd042d824e957971392d62beb7 (patch) | |
tree | a9fcbc22f9463837d9c936935c7ef36bcd1cbdd9 | |
parent | e2e1561a15c76bc9089248ab63c9ac74325e13da (diff) | |
download | cpython-6b1e43b7bcbb85bd042d824e957971392d62beb7.zip cpython-6b1e43b7bcbb85bd042d824e957971392d62beb7.tar.gz cpython-6b1e43b7bcbb85bd042d824e957971392d62beb7.tar.bz2 |
Issue #5829: complex('1e500') shouldn't raise OverflowError
-rw-r--r-- | Lib/test/test_complex.py | 7 | ||||
-rw-r--r-- | Misc/NEWS | 4 | ||||
-rw-r--r-- | Objects/complexobject.c | 4 |
3 files changed, 13 insertions, 2 deletions
diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py index 43282d6..f621186 100644 --- a/Lib/test/test_complex.py +++ b/Lib/test/test_complex.py @@ -409,6 +409,13 @@ class ComplexTest(unittest.TestCase): @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"), + "test requires IEEE 754 doubles") def test_repr_roundtrip(self): vals = [0.0, 1e-500, 1e-315, 1e-200, 0.0123, 3.1415, 1e50, INF, NAN] vals += [-v for v in vals] @@ -12,6 +12,10 @@ What's New in Python 3.1 release candidate 1? 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 #5994: the marshal module now has docstrings. diff --git a/Objects/complexobject.c b/Objects/complexobject.c index b904cc4..30d8b52 100644 --- a/Objects/complexobject.c +++ b/Objects/complexobject.c @@ -799,7 +799,7 @@ complex_subtype_from_string(PyTypeObject *type, PyObject *v) */ /* first look for forms starting with <float> */ - z = PyOS_string_to_double(s, &end, PyExc_OverflowError); + z = PyOS_string_to_double(s, &end, NULL); if (z == -1.0 && PyErr_Occurred()) { if (PyErr_ExceptionMatches(PyExc_ValueError)) PyErr_Clear(); @@ -812,7 +812,7 @@ complex_subtype_from_string(PyTypeObject *type, PyObject *v) if (*s == '+' || *s == '-') { /* <float><signed-float>j | <float><sign>j */ x = z; - y = PyOS_string_to_double(s, &end, PyExc_OverflowError); + y = PyOS_string_to_double(s, &end, NULL); if (y == -1.0 && PyErr_Occurred()) { if (PyErr_ExceptionMatches(PyExc_ValueError)) PyErr_Clear(); |