[Python-checkins] r72803 - in python/branches/py3k: Lib/test/test_complex.py Misc/NEWS Objects/complexobject.c

mark.dickinson python-checkins at python.org
Wed May 20 20:41:04 CEST 2009


Author: mark.dickinson
Date: Wed May 20 20:41:04 2009
New Revision: 72803

Log:
Issue #5829: complex('1e500') shouldn't raise OverflowError

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

Modified: python/branches/py3k/Lib/test/test_complex.py
==============================================================================
--- python/branches/py3k/Lib/test/test_complex.py	(original)
+++ python/branches/py3k/Lib/test/test_complex.py	Wed May 20 20:41:04 2009
@@ -409,6 +409,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/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Wed May 20 20:41:04 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.
 
 - Issue #5994: the marshal module now has docstrings.

Modified: python/branches/py3k/Objects/complexobject.c
==============================================================================
--- python/branches/py3k/Objects/complexobject.c	(original)
+++ python/branches/py3k/Objects/complexobject.c	Wed May 20 20:41:04 2009
@@ -799,7 +799,7 @@
 	*/
 
 	/* 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 @@
 		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();


More information about the Python-checkins mailing list