Skip to content

Commit 5dde6d4

Browse files
committed
move float primitive into runtime
1 parent 60a73e1 commit 5dde6d4

11 files changed

+19
-20
lines changed

jscomp/runtime/.depend

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ caml_array.cmj : caml_array.cmi
22
caml_string.cmj : bs_string.cmj caml_string.cmi
33
caml_bytes.cmj : caml_bytes.cmi
44
caml_obj.cmj : js.cmj caml_array.cmj bs_obj.cmj caml_obj.cmi
5-
caml_int64.cmj : js.cmj caml_utils.cmj caml_int32.cmj bs_string.cmj \
6-
caml_int64.cmi
5+
caml_int64.cmj : js.cmj caml_utils.cmj caml_int32.cmj caml_float.cmj \
6+
bs_string.cmj caml_int64.cmi
77
caml_exceptions.cmj : js.cmj caml_builtin_exceptions.cmj bs_obj.cmj \
88
caml_exceptions.cmi
99
caml_js_exceptions.cmj : caml_exceptions.cmj

jscomp/runtime/bs_stdlib_mini.mli

-8
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,6 @@ external ( -. ) : float -> float -> float = "%subfloat"
6565
external ( *. ) : float -> float -> float = "%mulfloat"
6666
external ( /. ) : float -> float -> float = "%divfloat"
6767

68-
69-
external log : float -> float = "log" [@@bs.val] [@@bs.scope "Math"]
70-
external ceil : float -> float = "ceil" [@@bs.val] [@@bs.scope "Math"]
71-
external floor : float -> float = "floor" [@@bs.val] [@@bs.scope "Math"]
72-
external exp : float -> float = "exp" [@@bs.val] [@@bs.scope "Math"]
73-
external sqrt : float -> float = "sqrt" [@@bs.val] [@@bs.scope "Math"]
74-
75-
7668
external float : int -> float = "%floatofint"
7769

7870
external int_of_float : float -> int = "%intoffloat"

jscomp/runtime/caml_float.ml

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929
external _LOG2E : float = "Math.LOG2E" [@@bs.val]
3030
external _LOG10E : float = "Math.LOG10E" [@@bs.val]
3131
external abs_float : float -> float = "Math.abs" [@@bs.val]
32-
external floor_float : float -> float = "Math.floor" [@@bs.val]
32+
external floor : float -> float = "Math.floor" [@@bs.val]
33+
external exp : float -> float = "exp" [@@bs.val] [@@bs.scope "Math"]
3334
external log : float -> float = "Math.log" [@@bs.val]
35+
external sqrt : float -> float = "sqrt" [@@bs.val] [@@bs.scope "Math"]
3436
external max_float : float -> float -> float = "Math.max" [@@bs.val]
3537
external min_float : float -> float -> float = "Math.min" [@@bs.val]
3638
external pow_float : base:float -> exp:float -> float = "Math.pow" [@@bs.val]
@@ -86,7 +88,7 @@ let caml_frexp_float (x: float): float * int =
8688
else begin
8789
let neg = x < 0. in
8890
let x' = ref (abs_float x) in
89-
let exp = ref (floor_float (_LOG2E *. log !x') +. 1.) in
91+
let exp = ref (floor (_LOG2E *. log !x') +. 1.) in
9092
begin
9193
x' := !x' *. pow_float ~base:2. ~exp:(-.(!exp));
9294
if !x' < 0.5 then begin

jscomp/runtime/caml_float.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828

2929
(** *)
30-
30+
external floor : float -> float = "Math.floor" [@@bs.val]
3131
val caml_int32_float_of_bits : int32 -> float
3232
val caml_int32_bits_of_float : float -> int32
3333

jscomp/runtime/caml_int64.ml

+4-2
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,9 @@ let rec of_float (x : float) : t =
319319
~hi:(Nativeint.of_float (x /. two_ptr_32_dbl))
320320

321321

322-
external log2 : float = "Math.LN2" [@@bs.val]
322+
external log2 : float = "LN2" [@@bs.val] [@@bs.scope "Math"]
323+
external log : float -> float = "log" [@@bs.val] [@@bs.scope "Math"]
324+
external ceil : float -> float = "ceil" [@@bs.val] [@@bs.scope "Math"]
323325
(* external maxFloat : float -> float -> float = "Math.max" [@@bs.val] *)
324326

325327
let rec div self other =
@@ -363,7 +365,7 @@ let rec div self other =
363365
(* assert false *)
364366
while ge !rem other do
365367
let approx = ref ( Pervasives.max 1.
366-
(floor (to_float !rem /. to_float other) )) in
368+
(Caml_float.floor (to_float !rem /. to_float other) )) in
367369
let log2 = ceil (log !approx /. log2) in
368370
let delta =
369371
if log2 <= 48. then 1.

jscomp/test/caml_format_test.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ var Int64 = require("../../lib/js/int64.js");
88
var $$Buffer = require("../../lib/js/buffer.js");
99
var Format = require("../../lib/js/format.js");
1010
var Printf = require("../../lib/js/printf.js");
11-
var Caml_float = require("../../lib/js/caml_float.js");
1211
var Caml_int64 = require("../../lib/js/caml_int64.js");
1312
var Pervasives = require("../../lib/js/pervasives.js");
1413
var Caml_format = require("../../lib/js/caml_format.js");
@@ -189,7 +188,7 @@ var suites = Pervasives.$at(from_of_string(of_string), Pervasives.$at(/* :: */[
189188
(function (param) {
190189
return /* Eq */Block.__(0, [
191190
true,
192-
Caml_float.caml_classify_float(Caml_format.caml_float_of_string("nan")) === /* FP_nan */4
191+
Pervasives.classify_float(Caml_format.caml_float_of_string("nan")) === /* FP_nan */4
193192
]);
194193
})
195194
],
@@ -213,7 +212,7 @@ var suites = Pervasives.$at(from_of_string(of_string), Pervasives.$at(/* :: */[
213212
(function (param) {
214213
return /* Eq */Block.__(0, [
215214
a,
216-
Caml_float.caml_classify_float(Caml_format.caml_float_of_string(b))
215+
Pervasives.classify_float(Caml_format.caml_float_of_string(b))
217216
]);
218217
})
219218
];

jscomp/test/float_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function from_pairs(ps) {
147147

148148
var float_compare = Caml_primitive.caml_float_compare;
149149

150-
var param = Caml_float.caml_classify_float(3);
150+
var param = Pervasives.classify_float(3);
151151

152152
Mt_global.collect_eq(test_id, suites, "File \"float_test.ml\", line 47, characters 5-12", param, /* FP_normal */0);
153153

jscomp/test/test_pervasive.js

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ var Pervasives$1 = /* module */[
5656
/* min_int */Pervasives.min_int,
5757
/* lnot */Pervasives.lnot,
5858
/* epsilon_float */Pervasives.epsilon_float,
59+
/* classify_float */Pervasives.classify_float,
5960
/* char_of_int */Pervasives.char_of_int,
6061
/* string_of_bool */Pervasives.string_of_bool,
6162
/* bool_of_string */Pervasives.bool_of_string,

jscomp/test/test_pervasives2.js

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ var List$1 = /* module */[
5757
/* min_int */Pervasives.min_int,
5858
/* lnot */Pervasives.lnot,
5959
/* epsilon_float */Pervasives.epsilon_float,
60+
/* classify_float */Pervasives.classify_float,
6061
/* char_of_int */Pervasives.char_of_int,
6162
/* string_of_bool */Pervasives.string_of_bool,
6263
/* bool_of_string */Pervasives.bool_of_string,
@@ -145,6 +146,7 @@ var U = /* module */[
145146
/* min_int */Pervasives.min_int,
146147
/* lnot */Pervasives.lnot,
147148
/* epsilon_float */Pervasives.epsilon_float,
149+
/* classify_float */Pervasives.classify_float,
148150
/* char_of_int */Pervasives.char_of_int,
149151
/* string_of_bool */Pervasives.string_of_bool,
150152
/* bool_of_string */Pervasives.bool_of_string,

jscomp/test/test_pervasives3.js

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var Pervasives$1 = /* module */[
1212
/* min_int */Pervasives.min_int,
1313
/* lnot */Pervasives.lnot,
1414
/* epsilon_float */Pervasives.epsilon_float,
15+
/* classify_float */Pervasives.classify_float,
1516
/* char_of_int */Pervasives.char_of_int,
1617
/* string_of_bool */Pervasives.string_of_bool,
1718
/* bool_of_string */Pervasives.bool_of_string,

lib/whole_compiler.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -95052,7 +95052,7 @@ let translate loc (prim_name : string)
9505295052
-> Js_long.max args
9505395053
| "caml_int32_float_of_bits"
9505495054
| "caml_int32_bits_of_float"
95055-
| "caml_classify_float"
95055+
9505695056
| "caml_modf_float"
9505795057
| "caml_ldexp_float"
9505895058
| "caml_frexp_float"

0 commit comments

Comments
 (0)