Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
That's a common issue when you have algorithms that iterate over a floating point interval (integration comes to mind). You either use steps of 1/8, 1/16 etc., that is the fastest solution. Or if you absolutely need 0.1, 0.01 etc. as steps, you take an integer as loop variable, and in the loop, you cast it to float and divide it by 10.0, 100.0 etc.
-
@crisz because there's a lot more Javascript developers who don't have the slightest idea about how a computer deals with their programs on a lower level.
Also because there's a lot more js developers.
Btw, I'm not saying js developers are less competent or whatever, just that on average, they are less aware of low level stuff.
console.log(0.47-0.01===0.46);
Output: false :/
That got me stuck for quite a while..
Learned more about floating point arithmetic and representation 😊
rant
float
arithmetic
floating point math
javascript