You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 4345 Reporter: brunodefraine Assigned to:@xclerc Status: closed (set by @xavierleroy on 2013-08-31T10:44:32Z) Resolution: fixed Priority: normal Severity: minor Version: 3.10.0 Fixed in version: 3.12.1+dev Category: -for Camlp4 use https://github.com/ocaml/camlp4/issues Related to:#3352#4767 Monitored by:@Chris00
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
The text was updated successfully, but these errors were encountered:
Original bug ID: 4345
Reporter: brunodefraine
Assigned to: @xclerc
Status: closed (set by @xavierleroy on 2013-08-31T10:44:32Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 3.10.0
Fixed in version: 3.12.1+dev
Category: -for Camlp4 use https://github.com/ocaml/camlp4/issues
Related to: #3352 #4767
Monitored by: @Chris00
Bug 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 ;;
While:
$ ocaml camlp4rf.cma
value pi = 3.14159265358979312 ;
value pi : float = 3.14159265359
float_of_string "3.14159265359" = pi ;
Similarly, consider `flo antiquotations:
$ ocaml camlp4rf.cma
open Camlp4.PreCast;
value _loc = Loc.ghost;
value pi = 3.14159265358979312;
<:expr<$`flo:pi$ >> ;
Camlp4.PreCast.Ast.ExFlo "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
The text was updated successfully, but these errors were encountered: