]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #5829: complex('1e-500') shouldn't raise an exception; also, fix indentation...
authorMark Dickinson <dickinsm@gmail.com>
Sat, 25 Apr 2009 13:28:26 +0000 (13:28 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Sat, 25 Apr 2009 13:28:26 +0000 (13:28 +0000)
Lib/test/test_complex.py
Misc/NEWS
Objects/complexobject.c

index ab3c1d1d2dae0baec6168453847872b2734e774d..6ec286a46d20abb57aa2e93231e85f1240ca558a 100644 (file)
@@ -202,6 +202,9 @@ class ComplexTest(unittest.TestCase):
         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)
index e1baa8a1117614a53f9c8cbc7e798268fe34a310..1d8c051d646726f1ea1e6e2c698b43b15a7f1059 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 3.0.2?
 Core and Builtins
 -----------------
 
+- Issue #5829: complex('1e-500') no longer raises an exception
+
 - Issue #5604: non-ASCII characters in module name passed to
   imp.find_module() were converted to UTF-8 while the path is
   converted to the default filesystem encoding, causing nonsense.
index 207ecdd07fe967103c38cdcd0aa75bc9a9cafac9..a0dcea0152fc453d7e06d46dd8aafcda7227b04b 100644 (file)
@@ -850,16 +850,16 @@ complex_subtype_from_string(PyTypeObject *type, PyObject *v)
                        }
                        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') {