@@ -386,8 +386,6 @@ let source_location ctx position pc =
386
386
387
387
(* ***)
388
388
389
- let float_const f = J. ENum (J.Num. of_float (Int64. float_of_bits f))
390
-
391
389
let s_var name = J. EVar (J. ident (Utf8_string. of_string_exn name))
392
390
393
391
let runtime_fun ctx name =
@@ -398,6 +396,20 @@ let runtime_fun ctx name =
398
396
J. dot (J. EVar (J. V runtime)) name
399
397
| None -> s_var name
400
398
399
+ let float_const ctx bits =
400
+ let f = Int64. float_of_bits bits in
401
+ match Float. classify_float f with
402
+ | FP_nan ->
403
+ let targetint x = J. ENum (J.Num. of_string_unsafe (Targetint. to_string_16 x)) in
404
+ let p = Share. get_prim (runtime_fun ctx) " jsoo_float_of_bits" ctx.Ctx. share in
405
+ let lo = targetint (Targetint. of_int32_truncate (Int64. to_int32 bits))
406
+ and hi =
407
+ targetint
408
+ (Targetint. of_int32_truncate (Int64. to_int32 (Int64. shift_right bits 32 )))
409
+ in
410
+ J. call p [ lo; hi ] J. N
411
+ | FP_zero | FP_normal | FP_subnormal | FP_infinite -> J. ENum (J.Num. of_float f)
412
+
401
413
let str_js_byte s =
402
414
let b = Buffer. create (String. length s) in
403
415
String. iter s ~f: (function
@@ -468,11 +480,11 @@ let rec constant_rec ~ctx x level instrs =
468
480
match s with
469
481
| Byte x -> Share. get_byte_string str_js_byte x ctx.Ctx. share, instrs
470
482
| Utf (Utf8 x ) -> Share. get_utf_string str_js_utf8 x ctx.Ctx. share, instrs)
471
- | Float f -> float_const f, instrs
483
+ | Float f -> float_const ctx f, instrs
472
484
| Float_array a ->
473
485
( Mlvalue.Array. make
474
486
~tag: Obj. double_array_tag
475
- ~args: (Array. to_list (Array. map a ~f: (fun x -> J. Element (float_const x))))
487
+ ~args: (Array. to_list (Array. map a ~f: (fun x -> J. Element (float_const ctx x))))
476
488
, instrs )
477
489
| Int64 i ->
478
490
let p =
0 commit comments