16
16
(* type 'a option = None | Some of 'a *)
17
17
18
18
(* Exceptions *)
19
- #if BS
20
- #else
21
- external register_named_value : string -> 'a -> unit
22
- = " caml_register_named_value"
23
-
24
- let () =
25
- (* for asmrun/fail.c *)
26
- register_named_value " Pervasives.array_bound_error"
27
- (Invalid_argument " index out of bounds" )
28
- #end
29
19
30
20
external raise : exn -> 'a = " %raise"
31
21
external raise_notrace : exn -> 'a = " %raise_notrace"
@@ -61,16 +51,8 @@ external ( > ) : 'a -> 'a -> bool = "%greaterthan"
61
51
external ( < = ) : 'a -> 'a -> bool = " %lessequal"
62
52
external ( > = ) : 'a -> 'a -> bool = " %greaterequal"
63
53
external compare : 'a -> 'a -> int = " %compare"
64
-
65
- #if BS
66
54
external min : 'a -> 'a -> 'a = " %bs_min"
67
55
external max : 'a -> 'a -> 'a = " %bs_max"
68
- #else
69
- let min x y = if x < = y then x else y
70
- let max x y = if x > = y then x else y
71
-
72
- #end
73
-
74
56
external ( == ) : 'a -> 'a -> bool = " %eq"
75
57
external ( != ) : 'a -> 'a -> bool = " %noteq"
76
58
@@ -117,34 +99,19 @@ external ( +. ) : float -> float -> float = "%addfloat"
117
99
external ( -. ) : float -> float -> float = " %subfloat"
118
100
external ( *. ) : float -> float -> float = " %mulfloat"
119
101
external ( /. ) : float -> float -> float = " %divfloat"
120
- #if BS
102
+
121
103
external ( ** ) : float -> float -> float = " pow" [@@ bs.val] [@@ bs.scope " Math" ]
122
104
external exp : float -> float = " exp" [@@ bs.val][@@ bs.scope "Math" ]
123
- #else
124
- external ( ** ) : float -> float -> float = " caml_power_float" " pow"
125
- [@@ unboxed] [@@ noalloc]
126
- external exp : float -> float = " caml_exp_float" " exp" [@@ unboxed] [@@ noalloc]
127
- #end
128
105
external expm1 : float -> float = " caml_expm1_float" " caml_expm1"
129
106
[@@ unboxed] [@@ noalloc]
130
- #if BS
107
+
131
108
external acos : float -> float = " acos" [@@ bs.val] [@@ bs.scope "Math" ]
132
109
external asin : float -> float = " asin" [@@ bs.val] [@@ bs.scope "Math" ]
133
110
external atan : float -> float = " atan" [@@ bs.val] [@@ bs.scope "Math" ]
134
111
external atan2 : float -> float -> float = " atan2" [@@ bs.val] [@@ bs.scope "Math" ]
135
- #else
136
- external acos : float -> float = " caml_acos_float" " acos"
137
- [@@ unboxed] [@@ noalloc]
138
- external asin : float -> float = " caml_asin_float" " asin"
139
- [@@ unboxed] [@@ noalloc]
140
- external atan : float -> float = " caml_atan_float" " atan"
141
- [@@ unboxed] [@@ noalloc]
142
- external atan2 : float -> float -> float = " caml_atan2_float" " atan2"
143
- [@@ unboxed] [@@ noalloc]
144
- #end
145
112
external hypot : float -> float -> float
146
113
= " caml_hypot_float" " caml_hypot" [@@ unboxed] [@@ noalloc]
147
- #if BS
114
+
148
115
external cos : float -> float = " cos" [@@ bs.val] [@@ bs.scope "Math" ]
149
116
external cosh : float -> float = " cosh" [@@ bs.val] [@@ bs.scope "Math" ]
150
117
external log : float -> float = " log" [@@ bs.val] [@@ bs.scope "Math" ]
@@ -158,29 +125,6 @@ external tanh : float -> float = "tanh" [@@bs.val] [@@bs.scope "Math"]
158
125
external ceil : float -> float = " ceil" [@@ bs.val] [@@ bs.scope "Math" ]
159
126
external floor : float -> float = " floor" [@@ bs.val] [@@ bs.scope "Math" ]
160
127
external abs_float : float -> float = " abs" [@@ bs.val] [@@ bs.scope "Math" ]
161
- #else
162
- external cos : float -> float = " caml_cos_float" " cos" [@@ unboxed] [@@ noalloc]
163
- external cosh : float -> float = " caml_cosh_float" " cosh"
164
- [@@ unboxed] [@@ noalloc]
165
- external log : float -> float = " caml_log_float" " log" [@@ unboxed] [@@ noalloc]
166
- external log10 : float -> float = " caml_log10_float" " log10"
167
- [@@ unboxed] [@@ noalloc]
168
- external log1p : float -> float = " caml_log1p_float" " caml_log1p"
169
- [@@ unboxed] [@@ noalloc]
170
- external sin : float -> float = " caml_sin_float" " sin" [@@ unboxed] [@@ noalloc]
171
- external sinh : float -> float = " caml_sinh_float" " sinh"
172
- [@@ unboxed] [@@ noalloc]
173
- external sqrt : float -> float = " caml_sqrt_float" " sqrt"
174
- [@@ unboxed] [@@ noalloc]
175
- external tan : float -> float = " caml_tan_float" " tan" [@@ unboxed] [@@ noalloc]
176
- external tanh : float -> float = " caml_tanh_float" " tanh"
177
- [@@ unboxed] [@@ noalloc]
178
- external ceil : float -> float = " caml_ceil_float" " ceil"
179
- [@@ unboxed] [@@ noalloc]
180
- external floor : float -> float = " caml_floor_float" " floor"
181
- [@@ unboxed] [@@ noalloc]
182
- external abs_float : float -> float = " %absfloat"
183
- #end
184
128
external copysign : float -> float -> float
185
129
= " caml_copysign_float" " caml_copysign"
186
130
[@@ unboxed] [@@ noalloc]
@@ -195,34 +139,14 @@ external float_of_int : int -> float = "%floatofint"
195
139
external truncate : float -> int = " %intoffloat"
196
140
external int_of_float : float -> int = " %intoffloat"
197
141
198
- #if BS (* better unused finding *)
199
- #else
200
- external float_of_bits : int64 -> float
201
- = " caml_int64_float_of_bits" " caml_int64_float_of_bits_unboxed"
202
- [@@ unboxed] [@@ noalloc]
203
- #end
204
- #if BS
142
+
205
143
let infinity = 0x1 p2047
206
144
let neg_infinity = - 0x1 p2047
207
145
external nan : float = " NaN"
208
146
[@@ bs.val] [@@ bs.scope "Number" ]
209
147
let max_float = 1.79769313486231571e+308 (* 0x1.ffff_ffff_ffff_fp+1023*)
210
148
let min_float = 2.22507385850720138e-308 (* 0x1p-1022 *)
211
149
let epsilon_float = 2.22044604925031308e-16 (* 0x1p-52 *)
212
- #else
213
- let infinity =
214
- float_of_bits 0x7F_F0_00_00_00_00_00_00L
215
- let neg_infinity =
216
- float_of_bits 0xFF_F0_00_00_00_00_00_00L
217
- let nan =
218
- float_of_bits 0x7F_F0_00_00_00_00_00_01L
219
- let max_float =
220
- float_of_bits 0x7F_EF_FF_FF_FF_FF_FF_FFL
221
- let min_float =
222
- float_of_bits 0x00_10_00_00_00_00_00_00L
223
- let epsilon_float =
224
- float_of_bits 0x3C_B0_00_00_00_00_00_00L
225
- #end
226
150
227
151
228
152
@@ -232,7 +156,7 @@ type fpclass =
232
156
| FP_zero
233
157
| FP_infinite
234
158
| FP_nan
235
- #if BS
159
+
236
160
let classify_float (x : float ) : fpclass =
237
161
if ([% raw{| isFinite| }] : _ -> _ [@bs] ) x [@ bs] then
238
162
if abs_float x > = (* 0x1p-1022 *) (* 2.22507385850720138e-308*) min_float then
@@ -243,10 +167,7 @@ let classify_float (x : float) : fpclass =
243
167
if ([% raw{| isNaN| }] : _ -> _ [@bs] ) x [@ bs] then
244
168
FP_nan
245
169
else FP_infinite
246
- #else
247
- external classify_float : (float [@ unboxed]) -> fpclass =
248
- " caml_classify_float" " caml_classify_float_unboxed" [@@ noalloc]
249
- #end
170
+
250
171
(* String and byte sequence operations -- more in modules String and Bytes *)
251
172
252
173
external string_length : string -> int = " %string_length"
@@ -285,10 +206,6 @@ type ('a, 'b) result = ('a, 'b) Belt.Result.t =
285
206
| Error of 'b
286
207
287
208
(* String conversion functions *)
288
- #if BS
289
- #else
290
- external format_int : string -> int -> string = " caml_format_int"
291
- #end
292
209
external format_float : string -> float -> string = " caml_format_float"
293
210
294
211
let string_of_bool b =
@@ -303,12 +220,9 @@ let bool_of_string_opt = function
303
220
| "false" -> Some false
304
221
| _ -> None
305
222
306
- #if BS
223
+
307
224
external string_of_int : int -> string = " String" [@@ bs.val]
308
- #else
309
- let string_of_int n =
310
- format_int " %d" n
311
- #end
225
+
312
226
external int_of_string : string -> int = " caml_int_of_string"
313
227
314
228
let int_of_string_opt s =
0 commit comments