Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

max_int, min_int and min_float do not have the correct values #3

Open
keigoi opened this Issue Nov 9, 2010 · 2 comments

Comments

Projects
None yet
2 participants

keigoi commented Nov 9, 2010

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
Owner

jaked commented Nov 9, 2010

Thank you for the bug report.

See the following commit for some discussion on this issue:

dsheets/ocamljs@7bb091f

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.

keigoi commented Nov 10, 2010

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment