Why 0.1 + 0.2 isn't 0.3: flip the 64 bits a computer uses for decimals

30seconds
Type 0.1 + 0.2 into almost any programming language and you get 0.30000000000000004. Nothing is broken. Computers count in powers of two, and a tenth is an endless repeating fraction in binary, so it has to be rounded to fit in 64 bits.
Flip the real bits of a double yourself and see the exact value they stand for, and learn how a rounding error this small helped cause a deadly missile failure in 1991.
Deep dive · 3 min
More in Computing
View all →
How a Bloom filter says "definitely not" using just a few bits
How can a computer check whether a word is on a huge list using only a few bits per entry? A Bloom filter flips a handful of switches for every word you add…
How one extra digit on your bank card catches your typos
The last digit of your bank card number isn't part of your account. It's a check digit, computed from the other fifteen by a recipe an IBM engineer patented in…
How computers fake grey using only black and white dots
Old Mac screens, cheap printers and some modern games can only show two colours: black and white. Yet they still draw soft shadows and smooth skies. The trick…
How a computer adds 7 + 1 using nothing but switches
A computer chip has no idea what numbers are. It only has switches: billions of transistors that are either on or off. Yet wire a few of those switches into…