I'm studying math and when programming by my own I'll have a bunch of redundant checks, even if it's just implementing something I just proved to always work.
If I'm stressed, say an exam, I'll skip any and all checka, even if I'm not even sure if the math is correct and won't accidentally summon a great old one.
Don't worry, it's not! It's always safe to manipulate integers up to the full value of the significand! In JavaScript, which uses IEEE-754 binary64, which effectively corresponds to 54-bit integers.
Bit operations on JS numbers cast them to 32 bits first, so a lot of people only think about the embedding of signed 32-bit two's complement. But through plain old addition, subtraction, multiplication, and division joined with Math.trunc, you can get a lot more precision!
I mean, that kind of error happens in every language. It's not JavaScript specific, it's part of the IEEE spec.
And integer addition (the mathematical category, not the type) will never have that problem, by the way. The example you're looking for is 0.1 + 0.2 == 0.3 -> false
Well when developing in a big team (or teamS) some redundant checks might not be the worst idea. Someone WILL break your interface and if you have some checks in place the culprit MAY see what he is doing wrong... MAYBE! (OK, chances are good he just delets your check) ;)
1.2k
u/[deleted] Feb 07 '19
https://github.com/kleampa/not-paid