-
Notifications
You must be signed in to change notification settings - Fork 44
Open
Description
We should reconsider our use of string_of_float in QCheck.Print.float in favor of Printf.sprintf "%F".
The former
- doesn't print legal OCaml syntax (e.g.,
infand-infbelow) - isn't consistent across architectures (on macOS, MinGW, and MSVC
-. nanprints asnan, but as-nanon Linux, Cygwin, and with musl)
Here's Linux's behaviour of QCheck.Print.float:
# #require "qcheck-core";;
# let examples = Float.[0.0; -0.0; pi; infinity; neg_infinity; nan; -. nan];;
# List.iter (fun f -> QCheck.Print.float f |> print_endline) examples;;
0.
-0.
3.14159265359
inf
-inf
nan
-nanwhereas Printf.sprintf "%F" is guaranteed to print legal OCaml by the manual
(- F : convert a floating-point argument to OCaml syntax ( dddd. or dddd.ddd or d.ddd e+-dd ).):
# List.iter (fun f -> Printf.printf "%F\n" f) examples;;
0.
-0.
3.14159265359
infinity
neg_infinity
nan
nanIf we would like to distinguish nans with the sign-bit set (this could be considered a float special case after all), perhaps it is possible to write a special case for it in our printer (e.g., printing it as -.nan uniformly)? 🤔
(Spotted in ocaml-multicore/multicoretests#565 and ocaml-multicore/multicoretests#566)
Metadata
Metadata
Assignees
Labels
No labels