Never trust the least significant bits of a floating point number, at least unless you know enough about the extent that you can trust them. But in general, don't.
A double precision floating point number carries roughly 16 digits, actually 52 binary bits of precision.
What happens when you add two numbers that are of different magnitude?
X0 = 1/3
X0 =
0.333333333333333
So X0 is 1/3. Not exactly because we cannot represent the fraction 1/3 exactly in binary. But that is not really pertinent here.
sprintf('%0.55f',X0)
ans =
'0.3333333333333333148296162562473909929394721984863281250'
Suppose we add and subtract delta?
delta = 100000.1
delta =
100000.1
X1 = X0 + delta - delta
X1 =
0.333333333328483
What happened? We added a number that was more than 1e5 times as large as X0. Stored in a double, that means we lose the bottom 5 digits of the sum. Subtracting delta off again, does not help, because we already lost that information. Once information is lost, it cannot be magically regained.
Best Answer