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
-
Is this another post implying that JS is the only language that hasn't solved the fundamental problem of floats not being able to represent all numbers?
-
@monzrmango depends on what you have been doing with the variables because rounding errors can add up. That's a complicated issue in numerics, and it requires thorough analysis of the algorithm.
But as very basic step, avoid 0.1 stuff with floats and better use 1/2, 1/4, 1/8 and so on, especially for any kind of step size or loop. Or use an integer loop variable, cast it to float and divide it by 10 in every loop run, though that is slower and still inaccurate - it's just that the error at least doesn't add up in the loop. -
7Raiden8786yThis is like a recurring topic on devRant 😂
Again, 0.2 it's periodic in binary, it will *never* be exact in any language/floating point implementation! As well as in math 0.999999999999999999 != 0.9periodic -
@kenogo there are no hamsters in India I figured they are fluffy rats so they eat meat
-
@JackToolsNet the result is still wrong, but there is almost no situation where you should use == over ===.
> 0.5 + 0.1 == 0.6
> true
> 0.1 + 0.2 == 0.3
> false
🙏🙏
joke/meme