After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 62012 - locale independent double/string conversion
locale independent double/string conversion
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
1.3.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2001-10-09 19:41 UTC by Alexander Larsson
Modified: 2011-02-18 15:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Proposed patch. (14.88 KB, patch)
2001-10-09 19:49 UTC, Alexander Larsson
none Details | Review
new version of the patch (14.75 KB, patch)
2001-10-24 16:30 UTC, Alexander Larsson
none Details | Review

Description Alexander Larsson 2001-10-09 19:41:03 UTC
We need functions for locale-independent coversion between doubles and
strings. The ones that exist are either locale-dependent, non-threadsafe,
or both.
Comment 1 Alexander Larsson 2001-10-09 19:49:36 UTC
Created attachment 5795 [details] [review]
Proposed patch.
Comment 2 Owen Taylor 2001-10-20 21:02:05 UTC
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.
  
   
Comment 3 Alexander Larsson 2001-10-24 16:30:09 UTC
Created attachment 5904 [details] [review]
new version of the patch
Comment 4 Owen Taylor 2001-10-24 18:52:16 UTC
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.