4 ms·
Serious question - has Javascript the language evolved any features for handling integer math correctly so expressions like 2*57 aren't silently rounded? I rea
by alyandon 3y ago
Serious question - has Javascript the language evolved any features for handling integer math correctly so expressions like 2*57 aren't silently rounded? I realize that in most cases Javascriopt is "good enough" for useful work but I've seen even senior engineers get tripped up by Javascript's corner cases when it comes to its handling of integer vs float.
- wk_end 3y agoThere's BigInt [0]. Probably less useful for this specific case, but possibly useful as well, are typed integer arrays [1]. [0] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... [1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Typed_arrays https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guid...
- alyandon 3y agoAh, very cool. Thanks.
- throwaway632 3y ago> handling integer math correctly JavaScript doesn't have integers. Everything is a float. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... Although it has BigInt now.
- alyandon 3y agoYes, I'm aware that internally it is using floating point representation and that is one of the main reasons I avoid using it for anything math related. However, I am now aware that BigInt() exists so thanks for the link.
- deleted 3y ago[deleted]