purescript/purescript-integers

fromNumberImpl does not work for very large ints

felixSchl opened this issue · 5 comments

return (n | 0) === n ? just(n) : nothing;

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.

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