[Python-checkins] r72805 - in python/trunk: Lib/test/test_complex.py Misc/NEWS Objects/complexobject.c

mark.dickinson python-checkins at python.org
Wed May 20 20:43:07 CEST 2009


Author: mark.dickinson
Date: Wed May 20 20:43:07 2009
New Revision: 72805

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

Modified:
   python/trunk/Lib/test/test_complex.py
   python/trunk/Misc/NEWS
   python/trunk/Objects/complexobject.c

Modified: python/trunk/Lib/test/test_complex.py
==============================================================================
--- python/trunk/Lib/test/test_complex.py	(original)
+++ python/trunk/Lib/test/test_complex.py	Wed May 20 20:43:07 2009
@@ -431,6 +431,13 @@
 
     @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]

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Wed May 20 20:43:07 2009
@@ -12,6 +12,10 @@
 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.
 
 - __instancecheck__ and __subclasscheck__ are now completely ignored on classic

Modified: python/trunk/Objects/complexobject.c
==============================================================================
--- python/trunk/Objects/complexobject.c	(original)
+++ python/trunk/Objects/complexobject.c	Wed May 20 20:43:07 2009
@@ -989,8 +989,6 @@
 	z = PyOS_ascii_strtod(s, &end);
 	if (end == s && errno == ENOMEM)
 		return PyErr_NoMemory();
-	if (errno == ERANGE && fabs(z) >= 1.0)
-		goto overflow;
 
 	if (end != s) {
 		/* all 4 forms starting with <float> land here */
@@ -1002,8 +1000,6 @@
 			y = PyOS_ascii_strtod(s, &end);
 			if (end == s && errno == ENOMEM)
 				return PyErr_NoMemory();
-			if (errno == ERANGE && fabs(y) >= 1.0)
-				goto overflow;
 			if (end != s)
 				/* <float><signed-float>j */
 				s = end;
@@ -1063,11 +1059,6 @@
 	PyErr_SetString(PyExc_ValueError,
 			"complex() arg is a malformed string");
 	return NULL;
-
-  overflow:
-	PyErr_SetString(PyExc_OverflowError,
-			"complex() arg overflow");
-	return NULL;
 }
 
 static PyObject *


More information about the Python-checkins mailing list