Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006701OCamlstandard librarypublic2014-12-10 11:072017-05-29 00:20
Reporterhhugo 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusacknowledgedResolutionopen 
PlatformOSOS Version
Product Version 
Target VersionlaterFixed in Version 
Summary0006701: string_of_float and float_of_string are locale dependent
Descriptionarchive from 2004, http://caml.inria.fr/pub/ml-archives/caml-list/2004/06/e8eba13a4e7977d4c49f83bb9ea0eff2.en.html [^]

- 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.
https://github.com/mjambon/yojson/issues/13 [^]
TagsNo tags attached.
Attached Files

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

-  Notes
(0013089)
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.
(0013399)
hhugo (reporter)
2015-03-06 06:07
edited on: 2015-03-06 06:08

see strtod_l
https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/strtod_l.3.html [^]
and printf_l
https://developer.apple.com/library/ios/documentation/System/Conceptual/ManPages_iPhoneOS/man3/printf_l.3.html [^]

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

cross reference https://github.com/mirage/mirage-platform/issues/118 [^]
(0015047)
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.
(0015048)
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.

(0017785)
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.
(0017817)
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..

Options:
- 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
(0017823)
ygrek (reporter)
2017-05-29 00:20

https://github.com/ocaml/ocaml/pull/1185 [^]

- 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
2017-05-29 00:20 ygrek Note Added: 0017823


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker