Floating Point Numbers - Computerphile

Channel:Computerphile · Length:9:16 · Published:2014-01-22 · Views:2545912

Watch on YouTube

Summary

Tom Scott explains for Computerphile how floating point numbers work, why moving the binary point is fast, and why it handles money badly.

Why HN recommends it

Recommended as a simple, fun explanation of why floating point gives odd errors like 0.1 + 0.2.

Tom Scott's fun and simple take on Floating Points is a good video explaining why such weird errors happen — HN, 2015

Information theory & signal processing · Computer architecture & CPUs

Subtitles (excerpt)

People expect computers to be entirely accurate and precise with numbers. You know, you grow up with calculators. You expect that if you type in: "0.1 + 0.2", you expect it to come out to "0.3". And sooner or later every programmer, as they're learning, tries something like that. And they type it into a programming language. Something like "0.1 + 0.2", and they will hit Enter, and what the computer will give them is something like "0.300000000...1". And at that point, they will have started to learn about floating point numbers, and they will be starting to tear their hair out. Floating point numbers are essentially scientific notation. For the uninitiated, let's say you're an astrophysicist, and you have the speed of light, which is this enormous number with eight 0s after it. And you want to multiply it by a tiny distance. It doesn't really matter what we're measuring here, it's just a big number and a small number. Let's say, 0.00000015. Let's say you want to multiply these two together. (I may have made this a bit deliberately easy.) You could try and do some really complicated maths and work it all out, but you don't need to. Because in scientific notation, this is 3 times 10 to the 8,

On Hacker News

Short answer, no decimal in binary and math is hard. :) Here's a couple handy videos explaining it: [VIDEO] [LINK] — microwavecamera, 2017-06
Recommended: Floating Point Numbers - Computerphile [VIDEO] Tom Scott's fun and simple take on Floating Points is a good video explaining why such weird errors happen — felipesabino, 2015-11
You should still not use MONEY in Postgres, even their own website says so [1]. I still wouldn't use floats/numerics/decimals to store currency either in any db generally, as said by others you're going to end up with inaccurate numbers [2]. Therefore using integers is in fact very good for this use-case, especially if you are in accounting or book-keeping! Source: I work for a Fintech company th… — mercxry, 2023-10

Related videos