Skip to content

Commit 0f60ea2

Browse files
committed
Test NaNs
1 parent 5f999cb commit 0f60ea2

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

compiler/tests-jsoo/test_nan.ml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
let none = Int64.float_of_bits 0x7ff0_1234_5678_90ABL
2+
3+
let sign_mask = 0x8000_0000_0000_0000L
4+
5+
let some x =
6+
if Float.is_nan x
7+
then if Int64.(logand (bits_of_float x) sign_mask = 0L) then nan else -.nan
8+
else x
9+
10+
let is_none t = Int64.equal (Int64.bits_of_float t) (Int64.bits_of_float none)
11+
12+
let () =
13+
assert (is_none none);
14+
let l = [ nan; -.nan; 1.; -7.; infinity; neg_infinity; 0.; none ] in
15+
List.iter (fun f -> assert (not (is_none (some f)))) l

0 commit comments

Comments
 (0)