In a previous problem, there was the equation:
e = 1 – 3*((4/3) – 1)
And the is not 0
, but rather:
e =2.2204e-16
I understand why this occures, for 4/3
cannot be represented exactly.
The closest representation of 4/3
is:
1.3333333333333332593184650249895639717578887939453125
And after the necessary operations, e =2.2204e-16
is obtained.
Now, I am having trouble understanding the odd behaviors in these equations involving e
:
1)
b = 1e-16 + 1 - 1e-16;
c = 1e-16 - 1e-16 + 1;
Here we expect b
to equal c
, but this isn't the case. I know there is something fishy going on with the order of operations and the error, but I don't exactly understand why b
doesn't equal c
.
2)
sqrt(1e-16 + 1) - 1;
ans=0
Now, I suspect when the subtraction is done, and since the operands are nearly equal, there was some sort of cancellation. But I am still a little confused and would appreciate a detailed explanation. Thank you.