GNOME Bugzilla – Bug 62012
locale independent double/string conversion
Last modified: 2011-02-18 15:47:37 UTC
We need functions for locale-independent coversion between doubles and strings. The ones that exist are either locale-dependent, non-threadsafe, or both.
Created attachment 5795 [details] [review] Proposed patch.
I think we should go ahead and add these functions. Some comments. - I absolutely hate the format argument to g_ascii_dtostr. If you are formatting for human consumption, then you don't want to use this function. If you are not formatting for human consumption, then you really, really should not be forced to enter "%.17g" G_ASCII_DTOSTR_BUF_SIZE Becomes useless when you force people to literally supply %.17h. If we absolutely have to have this feature, then we should have a _separate_ g_ascii_formatd or something that takes the format, and make the normal function convenient for normal uses. (People might suggest #define G_ASCII_DTOSTR_FORMAT "%.17g", or making NULL mean "%.17g. I don't think either is much of an improvement. Keeping it simple means eliminating that argument.) - errno is not reset to zero when there is no decimal point in g_ascii_strtod. I believe this is a bug. - The docs for g_strtod() should explain why you almost always want to use g_ascii_strtod() instead. - I wouldn't say "as an extra convenience" when referring to the errno resetting behavior. There are two possible behaviors for this function that would be correct: - errno is set exactly as in strtod(). (Unchanged unless an error occurs.) - errno is set as errno = 0; strtod(). We are using the latter one, we should say so, but it's not really an "extra feature"; to some extent, it's coding laziness on our part ;-) It might be worth including details about how overflow is detected- what is the value of errno afterwards, etc, since it would clarify what is meant. That's all I see offhand. Looks good, except for the format argument.
Created attachment 5904 [details] [review] new version of the patch
2001-10-24 Alex Larsson <alexl@redhat.com> * docs/reference/glib/glib-sections.txt: Add g_strtod & co. * docs/reference/glib/tmpl/string_utils.sgml: Add docs for G_ASCII_DTOSTR_BUF_SIZE. * glib/gstrfuncs.[ch]: Added g_ascii_strtod, g_ascii_dtostr and g_ascii_formatd. * tests/Makefile.am: * tests/strtod-test.c: Add tests for g_ascii_strtod & co.