Closed
Description
While trying to figure out some unexpected behavior with NaN
s, I've discovered the following:
Caml_obj
usesCaml.int_compare
to compare numbers, both ints and floats.Caml.int_compare
considersNaN > NaN
and any other value. (which is of course fine if it's never used onNaN
s, but it is)Caml.float_compare
considersNaN == NaN
.Caml.float_compare
considersNaN
less than any other value.Caml.obj.lessthan
andCaml_obj.greatherthan
usesCaml_obj.compare
, and therefore also considersNaN
the greatest of all values! This is inconsistent with both OCaml and JavaScript behaviour. ComparingNaN
to anything, in any way, should returnfalse
.
Simple repro:
// These will all print true
Js.log(compare(nan, nan) == 0) // Caml.float_compare
Js.log(compare(nan, 33.3) == -1) // Caml.float_compare
Js.log(compare(nan->Obj.magic, nan->Obj.magic) == 1) // Caml_obj.compare (which in turn uses Caml.int_compare on numbers)
Js.log(nan > nan == false) // inlined as >, correct behaviour
Js.log(nan->Obj.magic > nan->Obj.magic == true) // Canl_obj.greaterthan
Metadata
Metadata
Assignees
Labels
No labels