]> granicus.if.org Git - python/commitdiff
Issue #5829: complex('1e500') shouldn't raise OverflowError
authorMark Dickinson <dickinsm@gmail.com>
Wed, 20 May 2009 18:41:04 +0000 (18:41 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Wed, 20 May 2009 18:41:04 +0000 (18:41 +0000)
Lib/test/test_complex.py
Misc/NEWS
Objects/complexobject.c

index 43282d684b04bc3ec12b0158a8cbd09398f72313..f6211865049ee60f03b9ce22a5d9ac9f6fcb43b7 100644 (file)
@@ -407,6 +407,13 @@ class ComplexTest(unittest.TestCase):
             self.assertEquals(atan2(z1.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"),
                          "test requires IEEE 754 doubles")
     def test_repr_roundtrip(self):
index 7ecbd3f915e482b70ba23f33d8dd4061fd5c4e00..ea5d09025f51e091d26c5549c683cd2ec15694fc 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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.
index b904cc47c1048c1ece3e101e5d6b20b78d2f34fc..30d8b5216e0a8d2c6349297ba968a548c554cf88 100644 (file)
@@ -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();