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.,
inf and -inf below)
- isn't consistent across architectures (on macOS, MinGW, and MSVC
-. nan prints as nan, but as -nan on 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
-nan
whereas 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
nan
If 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)
We should reconsider our use of
string_of_floatinQCheck.Print.floatin favor ofPrintf.sprintf "%F".The former
infand-infbelow)-. nanprints asnan, but as-nanon Linux, Cygwin, and with musl)Here's Linux's behaviour of
QCheck.Print.float:whereas
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 ).):If we would like to distinguish
nans with the sign-bit set (this could be considered afloatspecial case after all), perhaps it is possible to write a special case for it in our printer (e.g., printing it as-.nanuniformly)? 🤔(Spotted in ocaml-multicore/multicoretests#565 and ocaml-multicore/multicoretests#566)