| Anonymous | Login | Signup for a new account | 2013-05-26 11:20 CEST | ![]() |
| Main | My View | View Issues | Change Log | Roadmap |
| View Issue Details [ Jump to Notes ] | [ Issue History ] [ Print ] | |||||||||||
| ID | Project | Category | View Status | Date Submitted | Last Update | |||||||
| 0004345 | OCaml | Camlp4 | public | 2007-07-17 11:46 | 2012-01-20 14:16 | |||||||
| Reporter | brunodefraine | |||||||||||
| Assigned To | xclerc | |||||||||||
| Priority | normal | Severity | minor | Reproducibility | always | |||||||
| Status | resolved | Resolution | fixed | |||||||||
| Platform | OS | OS Version | ||||||||||
| Product Version | 3.10.0 | |||||||||||
| Target Version | Fixed in Version | 3.12.1+dev | ||||||||||
| Summary | 0004345: Reduced precision when converting floats to strings | |||||||||||
| Description | First, consider the top-level printing of values: $ ocaml # let pi = 3.14159265358979312 ;; val pi : float = 3.14159265358979312 # float_of_string "3.14159265358979312" = pi ;; - : bool = true While: $ ocaml camlp4rf.cma # value pi = 3.14159265358979312 ; value pi : float = 3.14159265359 # float_of_string "3.14159265359" = pi ; - : bool = False Similarly, consider `flo antiquotations: $ ocaml camlp4rf.cma # open Camlp4.PreCast; # value _loc = Loc.ghost; # value pi = 3.14159265358979312; # <:expr< $`flo:pi$ >> ; - : Camlp4.PreCast.Ast.expr = Camlp4.PreCast.Ast.ExFlo <abstr> "3.14159265359" While it might not be possible to produce string versions whose float_of_string value always exactly equals the original float value, the precision of the currently produced versions is far below the precision of Ocaml's float type. | |||||||||||
| Additional Information | This is probably related to the usage of string_of_float to produce the string versions. Consider the following alternative, located inside typing/oprint.ml, and probably used by OCaml's standard toplevel: let float_repres f = match classify_float f with FP_nan -> "nan" | FP_infinite -> if f < 0.0 then "neg_infinity" else "infinity" | _ -> let s1 = Printf.sprintf "%.12g" f in if f = float_of_string s1 then valid_float_lexeme s1 else let s2 = Printf.sprintf "%.15g" f in if f = float_of_string s2 then valid_float_lexeme s2 else Printf.sprintf "%.18g" f | |||||||||||
| Tags | No tags attached. | |||||||||||
| Attached Files | ||||||||||||
Relationships |
|||||||||||
|
|||||||||||
Issue History |
|||
| Date Modified | Username | Field | Change |
| 2007-07-17 11:46 | brunodefraine | New Issue | |
| 2007-11-10 15:00 | xleroy | Status | new => assigned |
| 2007-11-10 15:00 | xleroy | Assigned To | => ertai |
| 2011-02-08 15:05 | xclerc | Assigned To | ertai => xclerc |
| 2011-02-08 15:05 | xclerc | Relationship added | related to 0004767 |
| 2011-02-08 15:08 | xclerc | Status | assigned => resolved |
| 2011-02-08 15:08 | xclerc | Fixed in Version | => 3.12.1+dev |
| 2011-02-08 15:08 | xclerc | Resolution | open => fixed |
| 2012-01-20 14:16 | doligez | Relationship added | related to 0001154 |
| Copyright © 2000 - 2011 MantisBT Group |