You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
I am inclined to set min_int and max_int to the proper values for 32 bit ints, to match the 32-bit behavior of the Javascript bit operations. Does that seem right to you?
For min_float, this is supposed to be handled (see caml_int64_float_of_bits in primitives.js) but must be wrong; I will take a look.
Oh, I didn't know that JavaScript bit operations work in that way! Yes I think that is right.
And sorry, for min_float I was wrong, it have the correct value!
However, for some reason (string_of_float min_float) is "0." in Safari. On the contrary, in Firefox it works fine. I will also track this down.
EDIT: I got it. Safari wrongly returns the value of the following expression
new Number(Number.MIN_VALUE).toExponential(12)
(which is a value to be turned into (float_of_string min_float)) as
"I.nfinity00000e+�74"
So this is not a defect in ocamljs, but a bug in Safari(webkit). Sorry!
EDIT: FYI: This problem is fixed in the current nightly builds of webkit.
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:
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
The text was updated successfully, but these errors were encountered: