Eli5: Programmers, why does “0.15 == 0.150000000000000001” equals = True after 15 zeros?

209 views

Eli5: Programmers, why does “0.15 == 0.150000000000000001” equals = True after 15 zeros?

In: 13

5 Answers

Anonymous 0 Comments

There are a few different ways that computers store numbers. When very common way is called “floating point”. It’s used in most calculators, things like Excel spreadsheets, and lots of other places.

Floating point has some really big advantages over other ways of storing numbers. They can store huge numbers – greater than the numbers of atoms in the universe – and tiny numbers – smaller than the size of a subatomic particle. Custom hardware allows for really quick calculations with floating point. Supercomputers use them. You might have heard of supercomputers having a certain number of “megaflops”. That stands for “million floating point operations per seconds”.

But floating point has one big drawback: precision. It cannot store numbers precisely. They are limited to a fixed number of bytes for each number. In your example, the number 0.150000000000000001 is represented in floating point as

00111110000110011001100110011010

The number that 0.15 is represented as

00111110000110011001100110011010

They are the same. Once the numbers have been converted into the floating point format, the computer has no way to tell whether it means 0.150000000000000001 or 0.15 or any other number very close to 0.15.

I wish I could use that meme of Jenna Fisher with two pictures saying “head office needs to you find the difference between these two numbers”. . . “They’re the same number”.

Edit: I did it. Possibly the worst meme ever created: https://i.imgflip.com/6iy40i.jpg

You are viewing 1 out of 5 answers, click here to view all answers.