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
The basic law of JavaScript numbers is that numbers as all double precision floating point numbers (aka. A "double")
Sure in most languages the default is an integer, but in JavaScript that's not the case. JS has a ton of fuck ups, but numbers are probably the most consistent part of it all.
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) ;)
105
u/TheOldTubaroo Feb 07 '19 edited Feb 07 '19
Isn't that pointless? Aren't all js numbers floats, so you don't need to worry about integer division?
And also clamping the opacity to [0,1] and then checking if opacity is greater than 0 and less than 1...