Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006701OCamlstandard librarypublic2014-12-10 11:072017-05-28 09:21
Assigned To 
PlatformOSOS Version
Product Version 
Target VersionlaterFixed in Version 
Summary0006701: string_of_float and float_of_string are locale dependent
Descriptionarchive from 2004, [^]

- one need to document functions that rely on C code being platform/locale/.. dependent.
- provide alternative functions not containing this issue/feature
Additional Informationfor example, Yojson will be unable to read/parse JSON containing floats. [^]
TagsNo tags attached.
Attached Files

- Relationships
related to 0006296resolved inconsistent behavior of float_of_string (compare to "ints"_of_string) 

-  Notes
doligez (administrator)
2015-01-13 23:05

If at all possible, we should make these functions locale-independent and (maybe) provide some explicitly locale-dependent functions.
hhugo (reporter)
2015-03-06 06:07
edited on: 2015-03-06 06:08

see strtod_l [^]
and printf_l [^]

hhugo (reporter)
2015-06-08 14:36

cross reference [^]
xleroy (administrator)
2015-12-05 12:02

I'm postponing this PR to 'later', as there is no simple solution. For reference, here are some options:

- Use strtod_l when available. But it's not widely available, e.g. it's not in Linux/Glibc.
- Use setlocale() before strtod() to select the C locale, then use setlocale() again to restore the locale. Problem: probably expensive; not nice for multithreaded programs.
- Use localeconv() to determine the current "radix character" (= decimal point), then rewrite the string before calling strtod() to replace "." by the radix character. Yuck.
- Drop strtod() entirely and embark a portable reimplementation. Problem: that's an awful lot of code.
xleroy (administrator)
2015-12-05 12:26
edited on: 2015-12-05 12:37

Contradicting myself: strtod_l is indeed available in Linux/Glibc, it's just that it has no man page on my Linux installation. Perhaps it could be used, as a best effort.

markghayden (reporter)
2017-05-09 05:38

Is there any progress on this? We have a German user on Ubuntu with issue because Yojson rejects valid JSON file because of locale issue converting strings to floats.
ygrek (reporter)
2017-05-28 09:21

strtod_l will work, but afaics in 2017 there is no obvious solution for linux to printf floats in locale-independent way..

- vsnprintf_l seems only available in bsd, but not linux
- uselocale() to change thread locale around all vsnprintf calls.. (or maybe around all entries into ocaml runtime?). It avoids threads race condition, but still feels heavy (we could maybe use Printf machinery to pass a flag if format contains float conversion?)
- localeconv() decimal point rewriting, same yuck

- Issue History
Date Modified Username Field Change
2014-12-10 11:07 hhugo New Issue
2015-01-08 23:49 doligez Status new => acknowledged
2015-01-13 23:05 doligez Note Added: 0013089
2015-01-13 23:05 doligez Target Version => 4.02.3+dev
2015-01-15 18:56 doligez Relationship added related to 0006296
2015-03-06 06:07 hhugo Note Added: 0013399
2015-03-06 06:08 hhugo Note Edited: 0013399 View Revisions
2015-06-08 14:36 hhugo Note Added: 0014038
2015-07-10 17:47 doligez Target Version 4.02.3+dev => 4.03.0+dev / +beta1
2015-12-05 12:02 xleroy Note Added: 0015047
2015-12-05 12:02 xleroy Target Version 4.03.0+dev / +beta1 => later
2015-12-05 12:26 xleroy Note Added: 0015048
2015-12-05 12:37 xleroy Note Edited: 0015048 View Revisions
2016-12-08 10:35 shinwell Category OCaml runtime system => OCaml standard library
2017-02-23 16:43 doligez Category OCaml standard library => standard library
2017-05-09 05:38 markghayden Note Added: 0017785
2017-05-28 09:21 ygrek Note Added: 0017817

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker