-
Notifications
You must be signed in to change notification settings - Fork 13
Description
Pervasives.max_int and min_int have the following incorrect value, respectively: 1073741823 and 1073741824.
They are apparently not maximum or minimum integer in the JavaScript.
Though this might not be a bug in ocamljs.
The root cause is the definition in the stdlib/pervasives.ml in the OCaml distribution:
let min_int = 1 lsl (if 1 lsl 31 = 0 then 30 else 62)
let max_int = min_int - 1
which, if directly compiled into JS by ocamljs, will turn into a wrong value.
(For the meantime, I'm using this command to replace them with the correct value:
cat target-tmp.js |
gsed -E -e 's/var (min_int$$[0-9]+)./var \1 = -Math.pow(2,53);/g'
-e 's/var (max_int$$[0-9]+)./var \1 = Math.pow(2,53);/g' > target.js
(This is in my Makefile so the each occurrence of dollar ($) sign is doubled)
Similarly, min_float is 0. because it is defined as
let min_float =
float_of_bits 0x00_10_00_00_00_00_00_00L