GNOME Bugzilla – Bug 156421
g_ascii_strtod broken by previous fix
Last modified: 2011-02-18 16:09:33 UTC
The fix for bug 138424 ended up breaking g_ascii_strtod for strings like "1e1". The "e1" never makes it to strtod. (Probably 2.4 branch too.)
Also broken for "NAN" and infinities. See section 7.19.6.1 in http://www.open-std.org/jtc1/sc22/wg14/www/docs/n869/n869.txt.gz A double argument representing an infinity is converted in one of the styles [-]inf or [-]infinity -- which style is implementation-defined. A double argument representing a NaN is converted in one of the styles [-]nan or [-]nan(n-char-sequence) -- which style, and the meaning of any n-char- sequence, is implementation-defined. The F conversion specifier produces INF, INFINITY, or NAN instead of inf, infinity, or nan, respectively.220)
Should be fixed now.
From visual inspection, it looks good. There is one thing it does not handle and that it probably never will: [#6] In other than the "C" locale, additional locale- specific subject sequence forms may be accepted. so g_ascii_strtod may accept things it should not. In practice I doubt that will happen and with a vague clause like the above there isn't anything we can do about it anyway.
now it fails on "-.75,0" in locale 'de'. The following patch appears to fix it: --- from-cvs/glib/glib/gstrfuncs.c Sun Nov 21 17:48:04 2004 +++ my-gtk/glib/glib/gstrfuncs.c Wed Nov 24 10:34:35 2004 @@ -386,7 +386,7 @@ end = p; } - else if (g_ascii_isdigit (*p)) + else if (g_ascii_isdigit (*p) || *p == '.') { while (g_ascii_isdigit (*p)) p++;
2004-11-25 Matthias Clasen <mclasen@redhat.com> * tests/strtod-test.c (main): Add a testcase for the previous fix. * glib/gstrfuncs.c (g_ascii_strtod): Make it work again for floats starting with a decimal point, like .75 (#156421, Hans Breuer)
*** Bug 160197 has been marked as a duplicate of this bug. ***