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

mark.dickinson python-checkins at python.org
Sat Apr 25 15:16:51 CEST 2009


Author: mark.dickinson
Date: Sat Apr 25 15:16:50 2009
New Revision: 71891

Log:
Issue #5829: complex('1e-500') shouldn't raise an exception.
Also fix some confusing indentation.


Modified:
   python/branches/release26-maint/Lib/test/test_complex.py
   python/branches/release26-maint/Misc/NEWS
   python/branches/release26-maint/Objects/complexobject.c

Modified: python/branches/release26-maint/Lib/test/test_complex.py
==============================================================================
--- python/branches/release26-maint/Lib/test/test_complex.py	(original)
+++ python/branches/release26-maint/Lib/test/test_complex.py	Sat Apr 25 15:16:50 2009
@@ -220,6 +220,9 @@
         self.assertAlmostEqual(complex("+1"), +1)
         self.assertAlmostEqual(complex("(1+2j)"), 1+2j)
         self.assertAlmostEqual(complex("(1.3+2.2j)"), 1.3+2.2j)
+        self.assertAlmostEqual(complex("1E-500"), 1e-500+0j)
+        self.assertAlmostEqual(complex("1e-500J"), 1e-500j)
+        self.assertAlmostEqual(complex("+1e-315-1e-400j"), 1e-315-1e-400j)
 
         class complex2(complex): pass
         self.assertAlmostEqual(complex(complex2(1+1j)), 1+1j)

Modified: python/branches/release26-maint/Misc/NEWS
==============================================================================
--- python/branches/release26-maint/Misc/NEWS	(original)
+++ python/branches/release26-maint/Misc/NEWS	Sat Apr 25 15:16:50 2009
@@ -12,6 +12,8 @@
 Core and Builtins
 -----------------
 
+- Issue #5829: complex('1e-500') no longer raises an exception
+
 - Issue #5787: object.__getattribute__(some_type, "__bases__") segfaulted on
   some builtin types.
 

Modified: python/branches/release26-maint/Objects/complexobject.c
==============================================================================
--- python/branches/release26-maint/Objects/complexobject.c	(original)
+++ python/branches/release26-maint/Objects/complexobject.c	Sat Apr 25 15:16:50 2009
@@ -995,16 +995,16 @@
 			}
 			errno = 0;
 			PyFPE_START_PROTECT("strtod", return 0)
-				z = PyOS_ascii_strtod(s, &end) ;
+			z = PyOS_ascii_strtod(s, &end) ;
 			PyFPE_END_PROTECT(z)
-				if (errno != 0) {
-					PyOS_snprintf(buffer, sizeof(buffer),
-					  "float() out of range: %.150s", s);
-					PyErr_SetString(
-						PyExc_ValueError,
-						buffer);
-					return NULL;
-				}
+			if (errno == ERANGE && fabs(z) >= 1.0) {
+				PyOS_snprintf(buffer, sizeof(buffer),
+					"float() out of range: %.150s", s);
+				PyErr_SetString(
+					PyExc_ValueError,
+					buffer);
+				return NULL;
+			}
 			s=end;
 			if  (*s=='J' || *s=='j') {
 


More information about the Python-checkins mailing list