Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

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
Open

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

keigoi opened this issue Nov 9, 2010 · 2 comments

Comments

@keigoi
Copy link

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
@jaked
Copy link
Owner

jaked commented Nov 9, 2010

Thank you for the bug report.

See the following commit for some discussion on this issue:

dsheets@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
Copy link
Author

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants