Overflow issue when converting integers near maxint
richcarl opened this issue · 1 comments
richcarl commented
10 * total + code - 0x30 needs to be 10 * total + (code - 0x30), otherwise this overflows the integer range when converting values close to maxint (2^53 - 1 = 9007199254740991 with a JS backend). For example:
> String.toInt "9007199254740945"
Just 9007199254740944 : Maybe Int
> String.toInt "9007199254740991"
Just 9007199254740992 : Maybe Int
I would expect this function to always give an exact result whenever the integer literal fits into the available range for integers, but this is currently not true.
github-actions commented
Thanks for reporting this! To set expectations:
- Issues are reviewed in batches, so it can take some time to get a response.
- Ask questions a community forum. You will get an answer quicker that way!
- If you experience something similar, open a new issue. We like duplicates.
Finally, please be patient with the core team. They are trying their best with limited resources.