# Why do floating point additions sometimes produce equal results? [duplicate]

I have tried two sentences on my computer :

2 + 10^(-18) == 2
2^(-55) + 2^(-57) == 2^(-55)


My computer gives TRUE and FALSE respectively. Why does the computer give two different results? Shouldn't the computer give the same output?

• 10^(-18) is around 2^(-60) – TEMLIB Mar 12 '16 at 13:29

Floating point numbers have limited accuracy. They are stored in the following way: $\pm 1.x_0\ldots x_{n-1} \times 2^y$ (here $x_0,\ldots,x_{n-1}$ are binary digits) for an appropriate $n$; the value of the exponent $y$ is also bounded. The value of $n$ and the bounds on $y$ depend on the exact type of the floating point number.
When you add $2$ and $10^{-18}$, the answer is rounded to $2$ since the contribution of $10^{-18}$ is too small to store in the number (i.e., $n$ is too small). When you add $2^{-55}$ and $2^{-57}$ there is no such problem: this is stored as $1.01 \times 2^{-55}$.