-
Notifications
You must be signed in to change notification settings - Fork 471
Closed
Description
While trying to figure out some unexpected behavior with NaNs, I've discovered the following:
Caml_objusesCaml.int_compareto compare numbers, both ints and floats.Caml.int_compareconsidersNaN > NaNand any other value. (which is of course fine if it's never used onNaNs, but it is)Caml.float_compareconsidersNaN == NaN.Caml.float_compareconsidersNaNless than any other value.Caml.obj.lessthanandCaml_obj.greatherthanusesCaml_obj.compare, and therefore also considersNaNthe greatest of all values! This is inconsistent with both OCaml and JavaScript behaviour. ComparingNaNto 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.greaterthanMetadata
Metadata
Assignees
Labels
No labels