Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upFixes Basics.truncate for values larger than 32 bit ints #842
Conversation
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
process-bot
Mar 7, 2017
Thanks for the pull request! Make sure it satisfies this checklist. My human colleagues will appreciate it!
Here is what to expect next, and if anyone wants to comment, keep these things in mind.
process-bot
commented
Mar 7, 2017
|
Thanks for the pull request! Make sure it satisfies this checklist. My human colleagues will appreciate it! Here is what to expect next, and if anyone wants to comment, keep these things in mind. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
witoldsz
commented
Apr 20, 2017
witoldsz
referenced this pull request
Apr 21, 2017
Closed
Provide a binding to the .toFixed API #417
rtfeldman
added
the
bug
label
Apr 21, 2017
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
harfangk
Jan 22, 2018
I ran into this issue myself today. I hope this would get merged soon!
By the way, there's also Math.trunc() function in ES5, which corresponds to this function, but of course it's supported on relatively newer browsers.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc
harfangk
commented
Jan 22, 2018
|
I ran into this issue myself today. I hope this would get merged soon! https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc |
Grannath commentedMar 7, 2017
The current native JavaScript implementation uses the
n | 0bit-wise operation to truncate the value. This is restricted by the definition of bit-wise operations. They are defined to operate on 32 bit signed integers.In general, JavaScript allows 64 bit floating point numbers. With these, integers can be represented up to
2^53 - 1aka Number.MAX_SAFE_INTEGER. By using a bit-wise operation, the usable range of Int in Elm is restricted artificially.The implementation is replaced here with
Math.ceilandMath.floordepending on the sign. Testing in a REPL now successfully evaluates e.g.truncate <| 2.45 * (2 ^ 33), which would have been impossible before.Such a restriction is a) unnecessary and b) unexpected. I highly suggest removing it.