diff --git a/jscomp/runtime/caml_int64.mli b/jscomp/runtime/caml_int64.mli index a35e6c5a8e..e52616634b 100644 --- a/jscomp/runtime/caml_int64.mli +++ b/jscomp/runtime/caml_int64.mli @@ -28,7 +28,7 @@ (** *) -type t (* = { lo : nativeint; hi : nativeint; } *) +type t val min_int : t val max_int : t val one : t @@ -77,7 +77,10 @@ val compare : t -> t -> int val float_of_bits : t -> float + +(** [bits_of_float fl] it is undefined behaivor when [f] is NaN*) val bits_of_float : float -> t + val get64 : string -> int -> t diff --git a/jscomp/stdlib-406/release.ninja b/jscomp/stdlib-406/release.ninja index 961cf19c69..3a9f2455cd 100644 --- a/jscomp/stdlib-406/release.ninja +++ b/jscomp/stdlib-406/release.ninja @@ -62,7 +62,7 @@ build stdlib-406/gc.cmj : cc_cmi stdlib-406/gc.ml | stdlib-406/gc.cmi stdlib-406 build stdlib-406/gc.cmi : cc stdlib-406/gc.mli | stdlib-406/pervasives.cmj others build stdlib-406/genlex.cmj : cc_cmi stdlib-406/genlex.ml | stdlib-406/bytes.cmj stdlib-406/char.cmj stdlib-406/genlex.cmi stdlib-406/hashtbl.cmj stdlib-406/list.cmj stdlib-406/stream.cmj stdlib-406/string.cmj others build stdlib-406/genlex.cmi : cc stdlib-406/genlex.mli | stdlib-406/pervasives.cmj stdlib-406/stream.cmi others -build stdlib-406/hashtbl.cmj : cc_cmi stdlib-406/hashtbl.ml | stdlib-406/array.cmj stdlib-406/hashtbl.cmi stdlib-406/lazy.cmj stdlib-406/obj.cmj stdlib-406/random.cmj stdlib-406/string.cmj stdlib-406/sys.cmj others +build stdlib-406/hashtbl.cmj : cc_cmi stdlib-406/hashtbl.ml | stdlib-406/array.cmj stdlib-406/hashtbl.cmi stdlib-406/lazy.cmj stdlib-406/random.cmj stdlib-406/string.cmj stdlib-406/sys.cmj others build stdlib-406/hashtbl.cmi : cc stdlib-406/hashtbl.mli | stdlib-406/pervasives.cmj others build stdlib-406/int32.cmj : cc_cmi stdlib-406/int32.ml | stdlib-406/int32.cmi stdlib-406/pervasives.cmj others build stdlib-406/int32.cmi : cc stdlib-406/int32.mli | stdlib-406/pervasives.cmj others diff --git a/jscomp/test/int64_test.js b/jscomp/test/int64_test.js index ab18da7bef..bf9f340ff8 100644 --- a/jscomp/test/int64_test.js +++ b/jscomp/test/int64_test.js @@ -2354,39 +2354,50 @@ function eq(loc, x, y) { } function id(loc, x) { - return eq(loc, Caml_int64.bits_of_float(Caml_int64.float_of_bits(x)), x); + var float_value = Caml_int64.float_of_bits(x); + var match = Pervasives.classify_float(float_value); + if (match >= 4) { + return /* () */0; + } else { + return eq(loc, Caml_int64.bits_of_float(float_value), x); + } } -eq("File \"int64_test.ml\", line 176, characters 5-12", Caml_int64.bits_of_float(0.3), /* int64 */[ +eq("File \"int64_test.ml\", line 181, characters 5-12", Caml_int64.bits_of_float(0.3), /* int64 */[ /* hi */1070805811, /* lo */858993459 ]); -eq("File \"int64_test.ml\", line 177, characters 5-12", Caml_int64.float_of_bits(/* int64 */[ +eq("File \"int64_test.ml\", line 182, characters 5-12", Caml_int64.float_of_bits(/* int64 */[ /* hi */1070805811, /* lo */858993459 ]), 0.3); -id("File \"int64_test.ml\", line 178, characters 5-12", /* int64 */[ +id("File \"int64_test.ml\", line 183, characters 5-12", /* int64 */[ /* hi */-1, /* lo */4294967295 ]); -id("File \"int64_test.ml\", line 179, characters 5-12", /* int64 */[ +id("File \"int64_test.ml\", line 184, characters 5-12", /* int64 */[ /* hi */-1, /* lo */4294967196 ]); -id("File \"int64_test.ml\", line 180, characters 5-12", /* int64 */[ +id("File \"int64_test.ml\", line 185, characters 5-12", /* int64 */[ /* hi */0, /* lo */4294967295 ]); -id("File \"int64_test.ml\", line 181, characters 5-12", /* int64 */[ +id("File \"int64_test.ml\", line 186, characters 5-12", /* int64 */[ /* hi */0, /* lo */536870911 ]); +id("File \"int64_test.ml\", line 187, characters 5-12", /* int64 */[ + /* hi */0, + /* lo */536870655 + ]); + Mt.from_pair_suites("Int64_test", suites$1[0]); exports.f = f; diff --git a/jscomp/test/int64_test.ml b/jscomp/test/int64_test.ml index 041bb10249..face420598 100644 --- a/jscomp/test/int64_test.ml +++ b/jscomp/test/int64_test.ml @@ -171,13 +171,19 @@ let test_id = ref 0 let eq loc x y = Mt.eq_suites ~test_id ~suites loc x y let id loc (x : int64) = - eq loc (Int64.bits_of_float (Int64.float_of_bits x)) x + (* This is not a round trip, since NaN is not distinguishable in JS*) + let float_value = (Int64.float_of_bits x) in + match classify_float float_value with + | FP_nan -> () + | _ -> + eq loc (Int64.bits_of_float float_value) x let () = eq __LOC__ (Int64.bits_of_float 0.3) 4599075939470750515L; eq __LOC__ (Int64.float_of_bits 4599075939470750515L) 0.3; id __LOC__ (-1L); id __LOC__ (-100L); id __LOC__ 0xff_ff_ff_ffL; - id __LOC__ 0x1f_ff_ff_ffL + id __LOC__ 0x1f_ff_ff_ffL; + id __LOC__ 0x1f_ff_fe_ffL ;; Mt.from_pair_suites __MODULE__ !suites diff --git a/scripts/prebuilt.js b/scripts/prebuilt.js index 87387b39db..35e7aa041b 100755 --- a/scripts/prebuilt.js +++ b/scripts/prebuilt.js @@ -1,3 +1,4 @@ +#!/usr/bin/env node //@ts-check var cp = require("child_process"); var path = require("path");