New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
string_of_float loosing precision #3352
Comments
Comment author: administrator string_of_float is just printf "%.12g", hence limited precision. An "exact" |
Comment author: @damiendoligez At this point, string_of_float is a quick-and-dirty function. If you need more precision, you should use printf and specify the number of digits. Maybe someday, someone will implement [Clinger1990] and [Steele1990] for OCaml and submit a patch, but don't hold your breath. @inproceedings{Clinger1990, @inproceedings{Steele1990, |
Comment author: @dbuenzli Somehow I still think it would be nice if : (float_of_string (string_of_float i)) = i could be true for all the integers i that can be represented exactly in OCaml's float value. These integers are in the interval [-2^53;2^53]. This could be achieved by using "%.16g", i.e. is true for : (float_of_string (Printf.sprintf "%.16g" i)) Best, Daniel |
Original bug ID: 1154
Reporter: administrator
Status: resolved (set by @damiendoligez on 2012-01-20T13:26:27Z)
Resolution: suspended
Priority: normal
Severity: feature
Category: ~DO NOT USE (was: OCaml general)
Related to: #8279 #4345
Monitored by: @dbuenzli @Chris00
Bug description
Full_Name: mattias waldau
Version: 3.04
OS: linux
Submission from: h175n2fls34o849.telia.com (217.208.235.175)
It seems that string_of_float is only working with float internally,
and not using double.
string_of_float (86928280876. +. 0.9513)
results in
86928280877
The text was updated successfully, but these errors were encountered: