I am merely trying to ascertain what might be causing the bug.
I am struggling to understand what alleged defects that you mentioned have not been explained.
First you wrote:
I'm just wondering if someone knows how Excel adjusts for that situation and why it breaks when you just add a 0 to the sum.
I explained that is part of the flawed design of the Excel "close to zero" heuristic. I wrote:
In some limited contexts, Excel arbitrarily considers two values as equal if they are "close enough"; and it considers their difference to be exactly zero if the actual difference is "close enough".
Microsoft does not define "close enough".
And I wrote:
In part, generally the heuristic applies (1) only to the last arithmetic operation, (2) only to addition of operands with opposite signs and to subtraction and comparison of operands with the same sign, and (3) only when both operands are non-zero.
Adding or subtracting zero violates rule #3.
I believe that completely explains "how Excel adjusts for that situation" and "why it breaks when you just add a 0".
Answers:
- when Excel deems the result is "close enough" to zero; and
- because the last operation is not an addition of non-zero operands with opposite signs, nor a difference between non-zero operands with the same sign.
-----
Later you wrote:
You can replicate it using these numbers {1.333, 1.225, -1.333, -1.225, 0}. If you include the 0 in your sum you get an incorrect value.
I explained:
Generally, most non-integers cannot be represented exactly in binary. And the representation of arithmetic results is limited to a fixed number of binary digits ("bits"); specifically, the sum of 53 consecutive powers of 2 times an exponential factor.
[....]
If you would like a detailed explanation for why that is the "correct" result due to the way that Excel represents number and performs arithmetic, I can break it down for you. Please let me know.
You responded dismissively: "I'm not looking for a lesson on IEEE. [....] I completely understand the limitations of IEEE".
Obviously, you do not. But that response blocked a more complete explanation for why =A1+A2-A1-A2+0 returns about -2.22E-16, not zero, when A1 is 1.333 and A2 is 1.225.
Nevertheless, I did demonstrate that is the correct result
within the limitations of IEEE binary representation by noting that SUM({1.333, 1.225, -1.333, -1.225}) returns about -2.22E-16, not zero.
In other words, it is not that adding zero returns an "incorrect" value. Instead, it is that adding zero blocks Excel from changing the true arithmetic result
within the limitations of IEEE binary representation.
To reinforce that point, note the following additional examples:
=
(A1+A2-A1-A2
) returns about -2.22E-16
and
=IF(10.1 - 10 = 0.1, TRUE) returns FALSE
(The first example defeats the "close to zero" heuristic because subtraction is no longer the last operation. In Excel's flawed design, the right parenthesis is!)
Both results are correct
within the limitations of IEEE binary representation.
I believe that explains, to the extent that you permitted, why "you get an incorrect value" (non-zero).
Answer: It is correct
within the limitations of IEEE binary representation.
-----
Granted, they are not the expected results based on decimal representation; and usually they are not the desired result.
And granted, there are reasonable algorithms and methods that Excel could implement to ameliorate some undesired effects of the limitations of IEEE binary representation. (The "close to zero" heuristic is not one of them.)
But Excel does not.