@@ -45,10 +45,12 @@ let shift_op l f =
45
45
| [ Int i; Int j ] -> Some (Int (f i (Targetint. to_int_exn j)))
46
46
| _ -> None
47
47
48
+ let float f : constant = Float (Int64. bits_of_float f)
49
+
48
50
let float_binop_aux (l : constant list ) (f : float -> float -> 'a ) : 'a option =
49
51
let args =
50
52
match l with
51
- | [ Float i; Float j ] -> Some (i, j)
53
+ | [ Float i; Float j ] -> Some (Int64. float_of_bits i, Int64. float_of_bits j)
52
54
| _ -> None
53
55
in
54
56
match args with
@@ -57,12 +59,12 @@ let float_binop_aux (l : constant list) (f : float -> float -> 'a) : 'a option =
57
59
58
60
let float_binop (l : constant list ) (f : float -> float -> float ) : constant option =
59
61
match float_binop_aux l f with
60
- | Some x -> Some (Float x)
62
+ | Some x -> Some (float x)
61
63
| None -> None
62
64
63
65
let float_unop (l : constant list ) (f : float -> float ) : constant option =
64
66
match l with
65
- | [ Float i ] -> Some (Float (f i ))
67
+ | [ Float i ] -> Some (float (f ( Int64. float_of_bits i) ))
66
68
| _ -> None
67
69
68
70
let bool' b = Int Targetint. (if b then one else zero)
@@ -71,7 +73,7 @@ let bool b = Some (bool' b)
71
73
72
74
let float_unop_bool (l : constant list ) (f : float -> bool ) =
73
75
match l with
74
- | [ Float i ] -> bool (f i )
76
+ | [ Float i ] -> bool (f ( Int64. float_of_bits i) )
75
77
| _ -> None
76
78
77
79
let float_binop_bool l f =
@@ -168,10 +170,10 @@ let eval_prim x =
168
170
| "caml_div_float" , _ -> float_binop l ( /. )
169
171
| "caml_fmod_float" , _ -> float_binop l mod_float
170
172
| "caml_int_of_float" , [ Float f ] -> (
171
- match Targetint. of_float_opt f with
173
+ match Targetint. of_float_opt ( Int64. float_of_bits f) with
172
174
| None -> None
173
175
| Some f -> Some (Int f))
174
- | "caml_float_of_int" , [ Int i ] -> Some (Float (Targetint. to_float i))
176
+ | "caml_float_of_int" , [ Int i ] -> Some (float (Targetint. to_float i))
175
177
(* Math *)
176
178
| "caml_neg_float" , _ -> float_unop l ( ~-. )
177
179
| "caml_abs_float" , _ -> float_unop l abs_float
@@ -209,16 +211,19 @@ let eval_prim x =
209
211
| "caml_erfc_float" , _ -> float_unop l Float. erfc
210
212
| "caml_nextafter_float" , _ -> float_binop l Float. next_after
211
213
| "caml_float_compare" , [ Float i; Float j ] ->
212
- Some (Int (Targetint. of_int_exn (Float. compare i j)))
214
+ Some
215
+ (Int
216
+ (Targetint. of_int_exn
217
+ (Float. compare (Int64. float_of_bits i) (Int64. float_of_bits j))))
213
218
| "caml_ldexp_float" , [ Float f; Int i ] ->
214
- Some (Float (ldexp f (Targetint. to_int_exn i)))
219
+ Some (float (ldexp ( Int64. float_of_bits f) (Targetint. to_int_exn i)))
215
220
(* int32 *)
216
- | "caml_int32_bits_of_float" , [ Float f ] -> int32 ( Int32. bits_of_float f)
217
- | "caml_int32_float_of_bits" , [ Int i ] ->
218
- Some (Float (Int32. float_of_bits ( Targetint. to_int32 i) ))
219
- | "caml_int32_float_of_bits " , [ Int32 i ] -> Some ( Float ( Int32. float_of_bits i))
220
- | "caml_int32_of_float" , [ Float f ] -> int32 (Int32. of_float f )
221
- | "caml_int32_to_float" , [ Int32 i ] -> Some (Float (Int32. to_float i))
221
+ | "caml_int32_bits_of_float" , [ Float f ] ->
222
+ int32 ( Int32. bits_of_float ( Int64. float_of_bits f))
223
+ | "caml_int32_float_of_bits" , [ Int32 i ] -> Some (float (Int32. float_of_bits i ))
224
+ | "caml_int32_of_float " , [ Float f ] ->
225
+ int32 (Int32. of_float ( Int64. float_of_bits f) )
226
+ | "caml_int32_to_float" , [ Int32 i ] -> Some (float (Int32. to_float i))
222
227
| "caml_int32_neg" , _ -> int32_unop l Int32. neg
223
228
| "caml_int32_add" , _ -> int32_binop l Int32. add
224
229
| "caml_int32_sub" , _ -> int32_binop l Int32. sub
@@ -240,13 +245,13 @@ let eval_prim x =
240
245
| "caml_nativeint_of_int32" , [ Int32 i ] -> Some (NativeInt i)
241
246
| "caml_nativeint_to_int32" , [ NativeInt i ] -> Some (Int32 i)
242
247
(* nativeint *)
243
- | "caml_nativeint_bits_of_float" , [ Float f ] -> nativeint (Int32. bits_of_float f)
244
- | "caml_nativeint_float_of_bits" , [ Int i ] ->
245
- Some (Float (Int32. float_of_bits (Targetint. to_int32 i)))
248
+ | "caml_nativeint_bits_of_float" , [ Float f ] ->
249
+ nativeint (Int32. bits_of_float (Int64. float_of_bits f))
246
250
| "caml_nativeint_float_of_bits" , [ NativeInt i ] ->
247
- Some (Float (Int32. float_of_bits i))
248
- | "caml_nativeint_of_float" , [ Float f ] -> nativeint (Int32. of_float f)
249
- | "caml_nativeint_to_float" , [ NativeInt i ] -> Some (Float (Int32. to_float i))
251
+ Some (float (Int32. float_of_bits i))
252
+ | "caml_nativeint_of_float" , [ Float f ] ->
253
+ nativeint (Int32. of_float (Int64. float_of_bits f))
254
+ | "caml_nativeint_to_float" , [ NativeInt i ] -> Some (float (Int32. to_float i))
250
255
| "caml_nativeint_neg" , _ -> nativeint_unop l Int32. neg
251
256
| "caml_nativeint_add" , _ -> nativeint_binop l Int32. add
252
257
| "caml_nativeint_sub" , _ -> nativeint_binop l Int32. sub
@@ -267,10 +272,11 @@ let eval_prim x =
267
272
| "caml_nativeint_to_int" , [ Int32 i ] -> Some (Int (Targetint. of_int32_truncate i))
268
273
| "caml_nativeint_of_int" , [ Int i ] -> nativeint (Targetint. to_int32 i)
269
274
(* int64 *)
270
- | "caml_int64_bits_of_float" , [ Float f ] -> int64 (Int64. bits_of_float f)
271
- | "caml_int64_float_of_bits" , [ Int64 i ] -> Some (Float (Int64. float_of_bits i))
272
- | "caml_int64_of_float" , [ Float f ] -> int64 (Int64. of_float f)
273
- | "caml_int64_to_float" , [ Int64 i ] -> Some (Float (Int64. to_float i))
275
+ | "caml_int64_bits_of_float" , [ Float f ] -> int64 f
276
+ | "caml_int64_float_of_bits" , [ Int64 i ] -> Some (Float i)
277
+ | "caml_int64_of_float" , [ Float f ] ->
278
+ int64 (Int64. of_float (Int64. float_of_bits f))
279
+ | "caml_int64_to_float" , [ Int64 i ] -> Some (float (Int64. to_float i))
274
280
| "caml_int64_neg" , _ -> int64_unop l Int64. neg
275
281
| "caml_int64_add" , _ -> int64_binop l Int64. add
276
282
| "caml_int64_sub" , _ -> int64_binop l Int64. sub
@@ -289,8 +295,7 @@ let eval_prim x =
289
295
Some (Int (Targetint. of_int_exn (Int64. compare i j)))
290
296
| "caml_int64_to_int" , [ Int64 i ] ->
291
297
Some (Int (Targetint. of_int32_truncate (Int64. to_int32 i)))
292
- | ( (" caml_int64_of_int" | " caml_int64_of_int32" | " caml_int64_of_nativeint" )
293
- , [ Int i ] ) -> int64 (Int64. of_int32 (Targetint. to_int32 i))
298
+ | "caml_int64_of_int" , [ Int i ] -> int64 (Int64. of_int32 (Targetint. to_int32 i))
294
299
| "caml_int64_to_int32" , [ Int64 i ] -> int32 (Int64. to_int32 i)
295
300
| "caml_int64_of_int32" , [ Int32 i ] -> int64 (Int64. of_int32 i)
296
301
| "caml_int64_to_nativeint" , [ Int64 i ] -> nativeint (Int64. to_int32 i)
@@ -435,7 +440,8 @@ let rec int_predicate deep info pred x (i : Targetint.t) =
435
440
let constant_js_equal a b =
436
441
match a, b with
437
442
| Int i , Int j -> Some (Targetint. equal i j)
438
- | Float a , Float b -> Some (Float. ieee_equal a b)
443
+ | Float a , Float b ->
444
+ Some (Float. ieee_equal (Int64. float_of_bits a) (Int64. float_of_bits b))
439
445
| NativeString a , NativeString b -> Some (Native_string. equal a b)
440
446
| String a , String b when Config.Flag. use_js_string () -> Some (String. equal a b)
441
447
| Int _ , Float _ | Float _ , Int _ -> None
0 commit comments