fromNumberImpl does not work for very large ints
felixSchl opened this issue · 5 comments
purescript-integers/src/Data/Int.js
Line 9 in 4ef3a1e
9114756780654345000 | 0 = -50578432
How about we use this suggested polyfill using Math.floor?
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
return typeof value === 'number' &&
isFinite(value) &&
Math.floor(value) === value;
I think this is working as it should - note that the Int type does not go larger than 2^31 - 1.
Ok, that's fair. I found this helpful to explain why: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER
The Int type is more restricted than that - the bitwise operators which you get in the generated code for adding or multiplying Int values are there to ensure that they remain 32-bit integers, so that overflow is predictable and so that the bitwise operators behave as you'd expect them to.
Thanks for the explanation