-
Notifications
You must be signed in to change notification settings - Fork 664
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
Int literals over "max unsigned 32bit" produce bad JS #1246
Comments
Just bumping this as the issue still persists in 0.17.1 a =
1000000000000000000000 var _user$project$Main$a = 3875820019684212736; |
On ubuntu 64bits, in elm-repl: > 10000000000000000000000000000
4477988020393345000 : number |
and : > round 1e10 --works
10000000000 : Int
> truncate 1e10 --fails
1410065408 : Int |
`Arithmetic.isPrime (1000 ^ 1000)` HANGS THE SYSTEM elm/compiler#1246
I looked into this. It seems to be a problem already in the AST, as the data type looks like this:
Haskell only guarantees 2^29-1 for Int, so it should be changed to Int64, or Double (as javascript uses Doubles for numbers anyway). |
The problem may also be fixed by using a 64-bit GHC to build the compiler, however, it should really work with a 32 bit version too. |
Why not a simple |
Javascript only uses Doubles anyway so anything more than that is not needed |
But anyway, everyone expects his constants to be found as-is in the generated javascript code. I think it costs nothing to use an |
The large Int literals in some of these tests result in errors (see elm/compiler#1246) that can't be resolved without editing the test file. Changing the Int literals to Floats is a simple and effective solution.
The large Int literals in some of these tests result in errors (see elm/compiler#1246) that can only be resolved by editing the test file. Changing the Int literals to Floats solves the issue. I think it would be best to fix it here even though it does make the exercise more interesting.
I am on Window 7 64 bit running Elm v0.16.
Someone on google groups (Max) produced the expected results on his OsX El Capitan computer.
It appears Elm compiler can only read string literal integers up to size (2^31 - 1) and set them reliably into the output javascript.
I don't currently have any issues with it not liking bigger than signed 32 bit string literal integers.
What surprised me is that there is no error from the compiler when it processed them it just silently truncates or wraps the value.
I would personally like to see errors for any string literal that isn't the same value produced as literal in the javascript code.
Examples Elm.
Example result in javascript.of above Elm
The text was updated successfully, but these errors were encountered: