Skip to content

Commit e537389

Browse files
committed
Patch Float.frexp significant stats where int_of_float is undefined on nan and infinity
1 parent 1a5bff0 commit e537389

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

test/core/QCheck2_tests.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,8 @@ module Stats = struct
10481048

10491049
let float_tests = (* Float.frexp nan (and infinity) is undefined and may return a 32766 exponent on Alpine *)
10501050
let float_expon_dist = ("exponent", fun f -> if Float.(is_nan f || is_infinite f) then 0 else snd (Float.frexp f)) in
1051-
let float_signif_dist = ("significant", fun f -> let s = fst (Float.frexp f) in int_of_float (s *. 1000000.)) in
1051+
let float_signif_dist = ("significant", fun f -> if Float.(is_nan f || is_infinite f) (* int_of_float is undefined on nan and infinity *)
1052+
then 0 else let s = fst (Float.frexp f) in int_of_float (s *. 1000000.)) in
10521053
let float_fpclass f = match Float.classify_float f with
10531054
| FP_normal -> "FP_normal"
10541055
| FP_subnormal -> "FP_subnormal"

test/core/QCheck_tests.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,9 +1111,10 @@ module Stats = struct
11111111
Test.make ~name:"exponential -10. dist" ~count:5_000 (add_stat float_dist (exponential (-10.))) (fun _ -> true);
11121112
]
11131113

1114-
let float_tests =
1114+
let float_tests = (* Float.frexp nan (and infinity) is undefined and may return a 32766 exponent on Alpine *)
11151115
let float_expon_dist = ("exponent", fun f -> if Float.(is_nan f || is_infinite f) then 0 else snd (Float.frexp f)) in
1116-
let float_signif_dist = ("significant", fun f -> let s = fst (Float.frexp f) in int_of_float (s *. 1000000.)) in
1116+
let float_signif_dist = ("significant", fun f -> if Float.(is_nan f || is_infinite f) (* int_of_float is undefined on nan and infinity *)
1117+
then 0 else let s = fst (Float.frexp f) in int_of_float (s *. 1000000.)) in
11171118
let float_fpclass f = match Float.classify_float f with
11181119
| FP_normal -> "FP_normal"
11191120
| FP_subnormal -> "FP_subnormal"

0 commit comments

Comments
 (0)