Skip to content

Commit 9a90f3d

Browse files
committed
continue to make stdlib_mini small
1 parent 13a57e6 commit 9a90f3d

12 files changed

+57
-47
lines changed

jscomp/runtime/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ caml_primitive.cmj: caml_primitive.cmi
2828
caml_int64.cmj : caml_obj.cmj
2929
bs_obj.cmj: js.cmi
3030
# or we can do a post-processing to add missing cmj dependency manually
31-
js_exn.cmj caml_js_exceptions.cmj : caml_exceptions.cmj
31+
caml_js_exceptions.cmj : caml_exceptions.cmj
3232
$(addsuffix .cmj, $(OTHERS)): caml_builtin_exceptions.cmj block.cmj js.cmj caml_primitive.cmj
3333

3434
## since we use ppx

jscomp/runtime/bs_stdlib_mini.mli

-8
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,6 @@ external floor : float -> float = "floor" [@@bs.val] [@@bs.scope "Math"]
7777
external exp : float -> float = "exp" [@@bs.val] [@@bs.scope "Math"]
7878
external sqrt : float -> float = "sqrt" [@@bs.val] [@@bs.scope "Math"]
7979

80-
type in_channel
81-
82-
type fpclass =
83-
FP_normal (** Normal number, none of the below *)
84-
| FP_subnormal (** Number very close to 0.0, has reduced precision *)
85-
| FP_zero (** Number is 0.0 or -0.0 *)
86-
| FP_infinite (** Number is positive or negative infinity *)
87-
| FP_nan (** Not a number: result of an undefined operation *)
8880

8981
external float : int -> float = "%floatofint"
9082

jscomp/runtime/caml_float.ml

+1-12
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ external pow_float : base:float -> exp:float -> float = "Math.pow" [@@bs.val]
3939

4040
let caml_int32_float_of_bits : int32 -> float = fun%raw x -> {|
4141
return new Float32Array(new Int32Array([x]).buffer)[0]
42-
|}
42+
|}
4343
(* let int32 = Int32_array.make [| x |] in
4444
let float32 = Float32_array.fromBuffer ( Int32_array.buffer int32) in
4545
Float32_array.unsafe_get float32 0 *)
@@ -50,17 +50,6 @@ let caml_int32_bits_of_float : float -> int32 = fun%raw x -> {|
5050
(* let float32 = Float32_array.make [|x|] in
5151
Int32_array.unsafe_get (Int32_array.fromBuffer (Float32_array.buffer float32)) 0 *)
5252

53-
let caml_classify_float x : fpclass =
54-
if FloatRT.isFinite x then
55-
if abs_float x >= 2.2250738585072014e-308 then
56-
FP_normal
57-
else if x <> 0. then FP_subnormal
58-
else FP_zero
59-
else
60-
if FloatRT.isNaN x then
61-
FP_nan
62-
else FP_infinite
63-
6453

6554
let caml_modf_float (x : float) : float * float =
6655
if FloatRT.isFinite x then

jscomp/runtime/caml_float.mli

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
val caml_int32_float_of_bits : int32 -> float
3232
val caml_int32_bits_of_float : float -> int32
3333

34-
val caml_classify_float : float -> fpclass
3534
val caml_modf_float : float -> float * float
3635

3736
val caml_ldexp_float : float -> int -> float

jscomp/runtime/caml_io.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525

2626

27-
27+
type in_channel
2828

2929

3030
(** *)

jscomp/stdlib-402/pervasives.ml

+14-1
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,21 @@ type fpclass =
210210
| FP_zero
211211
| FP_infinite
212212
| FP_nan
213+
#if BS then
214+
let classify_float (x : float) : fpclass =
215+
if [%raw{|isFinite|}] x [@bs] then
216+
if abs_float x >= 2.2250738585072014e-308 then
217+
FP_normal
218+
else if x <> 0. then FP_subnormal
219+
else FP_zero
220+
else
221+
if [%raw{|isNaN|}] x [@bs] then
222+
FP_nan
223+
else FP_infinite
224+
225+
#else
213226
external classify_float : float -> fpclass = "caml_classify_float"
214-
227+
#end
215228
(* String and byte sequence operations -- more in modules String and Bytes *)
216229

217230
external string_length : string -> int = "%string_length"

jscomp/stdlib-402/pervasives.mli

+4-1
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,11 @@ type fpclass =
597597
| FP_nan (** Not a number: result of an undefined operation *)
598598
(** The five classes of floating-point numbers, as determined by
599599
the {!Pervasives.classify_float} function. *)
600-
600+
#if BS then
601+
val classify_float : float -> fpclass
602+
#else
601603
external classify_float : float -> fpclass = "caml_classify_float"
604+
#end
602605
(** Return the class of the given floating-point number:
603606
normal, subnormal, zero, infinite, or not a number. *)
604607

jscomp/stdlib-406/pervasives.ml

+13-1
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,21 @@ type fpclass =
229229
| FP_zero
230230
| FP_infinite
231231
| FP_nan
232+
#if BS then
233+
let classify_float (x : float) : fpclass =
234+
if [%raw{|isFinite|}] x [@bs] then
235+
if abs_float x >= 0x1p-1022(* 2.2250738585072014e-308*) then
236+
FP_normal
237+
else if x <> 0. then FP_subnormal
238+
else FP_zero
239+
else
240+
if [%raw{|isNaN|}] x [@bs] then
241+
FP_nan
242+
else FP_infinite
243+
#else
232244
external classify_float : (float [@unboxed]) -> fpclass =
233245
"caml_classify_float" "caml_classify_float_unboxed" [@@noalloc]
234-
246+
#end
235247
(* String and byte sequence operations -- more in modules String and Bytes *)
236248

237249
external string_length : string -> int = "%string_length"

jscomp/stdlib-406/pervasives.mli

+4-1
Original file line numberDiff line numberDiff line change
@@ -652,9 +652,12 @@ type fpclass =
652652
| FP_nan (** Not a number: result of an undefined operation *)
653653
(** The five classes of floating-point numbers, as determined by
654654
the {!Pervasives.classify_float} function. *)
655-
655+
#if BS then
656+
val classify_float : float -> fpclass
657+
#else
656658
external classify_float : (float [@unboxed]) -> fpclass =
657659
"caml_classify_float" "caml_classify_float_unboxed" [@@noalloc]
660+
#end
658661
(** Return the class of the given floating-point number:
659662
normal, subnormal, zero, infinite, or not a number. *)
660663

lib/js/caml_float.js

+1-18
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,12 @@
33

44
function caml_int32_float_of_bits (x){
55
return new Float32Array(new Int32Array([x]).buffer)[0]
6-
};
6+
};
77

88
function caml_int32_bits_of_float (x){
99
return new Int32Array(new Float32Array([x]).buffer)[0]
1010
};
1111

12-
function caml_classify_float(x) {
13-
if (isFinite(x)) {
14-
if (Math.abs(x) >= 2.2250738585072014e-308) {
15-
return /* FP_normal */0;
16-
} else if (x !== 0) {
17-
return /* FP_subnormal */1;
18-
} else {
19-
return /* FP_zero */2;
20-
}
21-
} else if (isNaN(x)) {
22-
return /* FP_nan */4;
23-
} else {
24-
return /* FP_infinite */3;
25-
}
26-
}
27-
2812
function caml_modf_float(x) {
2913
if (isFinite(x)) {
3014
var neg = 1 / x < 0;
@@ -136,7 +120,6 @@ function caml_log10_float(x) {
136120

137121
exports.caml_int32_float_of_bits = caml_int32_float_of_bits;
138122
exports.caml_int32_bits_of_float = caml_int32_bits_of_float;
139-
exports.caml_classify_float = caml_classify_float;
140123
exports.caml_modf_float = caml_modf_float;
141124
exports.caml_ldexp_float = caml_ldexp_float;
142125
exports.caml_frexp_float = caml_frexp_float;

lib/js/camlinternalFormat.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ var $$String = require("./string.js");
99
var Caml_io = require("./caml_io.js");
1010
var Caml_obj = require("./caml_obj.js");
1111
var Caml_bytes = require("./caml_bytes.js");
12-
var Caml_float = require("./caml_float.js");
1312
var Caml_int32 = require("./caml_int32.js");
1413
var Pervasives = require("./pervasives.js");
1514
var Caml_format = require("./caml_format.js");
@@ -2957,7 +2956,7 @@ function convert_float(fconv, prec, x) {
29572956
}
29582957
};
29592958
};
2960-
var match = Caml_float.caml_classify_float(x);
2959+
var match = Pervasives.classify_float(x);
29612960
if (match !== 3) {
29622961
if (match >= 4) {
29632962
return "nan";

lib/js/pervasives.js

+17
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,22 @@ function lnot(x) {
4040

4141
var min_int = -2147483648;
4242

43+
function classify_float(x) {
44+
if (isFinite(x)) {
45+
if (Math.abs(x) >= 2.2250738585072014e-308) {
46+
return /* FP_normal */0;
47+
} else if (x !== 0) {
48+
return /* FP_subnormal */1;
49+
} else {
50+
return /* FP_zero */2;
51+
}
52+
} else if (isNaN(x)) {
53+
return /* FP_nan */4;
54+
} else {
55+
return /* FP_infinite */3;
56+
}
57+
}
58+
4359
function char_of_int(n) {
4460
if (n < 0 || n > 255) {
4561
throw [
@@ -562,6 +578,7 @@ exports.max_int = max_int;
562578
exports.min_int = min_int;
563579
exports.lnot = lnot;
564580
exports.epsilon_float = epsilon_float;
581+
exports.classify_float = classify_float;
565582
exports.char_of_int = char_of_int;
566583
exports.string_of_bool = string_of_bool;
567584
exports.bool_of_string = bool_of_string;

0 commit comments

Comments
 (0)