Have you performed simple arithmetic operations like 0.1 + 0.2? You might have gotten something strange: 0.1 + 0.2 = 0.30000000000000004.

19 points

Floating-point arithmetic is important to understand at least vaguely since it’s a pretty leaky abstraction. Fortunately, we don’t need a “✨Member-only story” on Medium to get acquainted with the underlying concepts.

permalink
report
reply
-4 points

It also includes a non member link

permalink
report
parent
reply
1 point

That link didn’t work for me.

permalink
report
parent
reply
12 points

Ugh, i thought this was a question, not a link. So i spent time googling for a good tutorial on floats (because I didn’t click the link)…

Now i hate myself, and this post.

permalink
report
reply
6 points

Don’t hate yourself. At least you searched it properly. See it this way, you learned from a failure more than anyone who did not fail. You are now stronger!

permalink
report
parent
reply
2 points

assuming i learned, lol :D

permalink
report
parent
reply
9 points
8 points

It’s how CPUs do floating point calculations. It’s not just javascript. Long story short, a float is stored in the format of one bit for the +/-, some bits for a base value (mantissa), and some bits for the exponent. As a result, some numbers aren’t quite representable exactly.

permalink
report
reply

Programming

!programming@programming.dev

Create post

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person’s post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you’re posting long videos try to add in some form of tldr for those who don’t want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



Community stats

  • 3.8K

    Monthly active users

  • 799

    Posts

  • 6.5K

    Comments