@@ -60,6 +60,14 @@ let rec list_split l len acc = match len,l with
6060 | 0 ,_ -> List. rev acc, l
6161 | _ ,x ::xs -> list_split xs (len-1 ) (x::acc)
6262
63+ let cut_exp_zero s =
64+ match String. split_on_char 'e' s with
65+ | [signif;exponent] ->
66+ (match exponent.[0 ] with (* int_of_string removes a leading '0' *)
67+ | '+' -> Printf. sprintf " %se+%i" signif (int_of_string exponent) (* keep a leading '+' *)
68+ | _ -> Printf. sprintf " %se%i" signif (int_of_string exponent)) (* keep a leading '-' *)
69+ | _ -> s
70+
6371exception Failed_precondition
6472(* raised if precondition is false *)
6573
@@ -924,7 +932,10 @@ module Print = struct
924932
925933 let bool = string_of_bool
926934
927- let float = string_of_float
935+ let float f = (* Windows workaround to avoid leading exponent zero such as "-1.00001604579e-010" *)
936+ if Sys. win32
937+ then string_of_float f |> cut_exp_zero
938+ else string_of_float f
928939
929940 let string s = Printf. sprintf " %S" s
930941
@@ -2118,10 +2129,6 @@ module Test = struct
21182129 (* print entries of the table, sorted by increasing index *)
21192130 let out = Buffer. create 128 in
21202131 (* Windows workaround to avoid annoying exponent zero such as "1.859e+018" *)
2121- let cut_exp_zero s =
2122- match String. split_on_char '+' s with
2123- | [signif;exponent] -> Printf. sprintf " %s+%i" signif (int_of_string exponent)
2124- | _ -> failwith " cut_exp_zero failed to parse scientific notation " ^ s in
21252132 let fmt_float f =
21262133 if f > 1e7 || f < - 1e7 then cut_exp_zero (Printf. sprintf " %.3e" f) else Printf. sprintf " %.2f" f in
21272134 Printf. bprintf out " stats %s:\n " name;
0 commit comments