Skip to content

Fix int64 test spec #3905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion jscomp/runtime/caml_int64.mli
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

(** *)

type t (* = { lo : nativeint; hi : nativeint; } *)
type t
val min_int : t
val max_int : t
val one : t
Expand Down Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion jscomp/stdlib-406/release.ninja
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 18 additions & 7 deletions jscomp/test/int64_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions jscomp/test/int64_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions scripts/prebuilt.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env node
//@ts-check
var cp = require("child_process");
var path = require("path");
Expand Down