]> granicus.if.org Git - python/commitdiff
SF#1391872
authorFredrik Lundh <fredrik@pythonware.com>
Thu, 29 Dec 2005 20:35:52 +0000 (20:35 +0000)
committerFredrik Lundh <fredrik@pythonware.com>
Thu, 29 Dec 2005 20:35:52 +0000 (20:35 +0000)
Floating point literals don't work in non-US locale in 2.5.  Patch and
new locale tests by Hye-Shik Chang.

Lib/test/test__locale.py
Python/ast.c

index ef4fe8d7172d7647468ff240048672097423aaef..abdb87e068a978f464714a6ee93a354186fed8ee 100644 (file)
@@ -97,6 +97,18 @@ class _LocaleTests(unittest.TestCase):
                                                 loc, set_locale))
 
 
+    def test_float_parsing(self):
+        # Bug #1391872: Test whether float parsing is okay on European
+        # locales.
+        for loc in candidate_locales:
+            try:
+                setlocale(LC_NUMERIC, loc)
+            except Error:
+                continue
+            self.assertEquals(int(eval('3.14') * 100), 314)
+            self.assertEquals(int(float('3.14') * 100), 314)
+
+
 
 def test_main():
     run_unittest(_LocaleTests)
index 93334dc18ecdecbfd28d5198670a29c6b6ba954b..745cda28c023370c5e9035a92cb6241afdb81537 100644 (file)
@@ -2773,7 +2773,7 @@ parsenumber(const char *s)
        if (imflag) {
                c.real = 0.;
                PyFPE_START_PROTECT("atof", return 0)
-               c.imag = atof(s);
+               c.imag = PyOS_ascii_atof(s);
                PyFPE_END_PROTECT(c)
                return PyComplex_FromCComplex(c);
        }
@@ -2781,7 +2781,7 @@ parsenumber(const char *s)
 #endif
        {
                PyFPE_START_PROTECT("atof", return 0)
-               dx = atof(s);
+               dx = PyOS_ascii_atof(s);
                PyFPE_END_PROTECT(dx)
                return PyFloat_FromDouble(dx);
        }