Re: Strange result in Excel 2000



While =($A$1+$B$1)-$C$1 returns zero, =(($A$1+$B$1)-$C$1) does not, and it is this later calculation that IF() is basing its decision on.

None of your numbers have exact binary representations, and hence must be approximated (just as 1/3 must be approximated in decimal). The (IEEE standard) binary approximations to the numbers involved in the final subtraction are
84.8999999999999914734871708787977695465087890625
-84.900000000000005684341886080801486968994140625
--------------------------------------------------
-0.0000000000000142108547152020037174224853515625
so Excel is exactly correct (given the approximations to the inputs) to report the answer for =(($A$1+$B$1)-$C$1) as -1.4210854715202E-14, and IF is correct to report that the result is not zero. And almost all other general purpose software will behave in the same manner. The real mystery is why =($A$1+$B$1)-$C$1 claims that the result is zero.


The key to that mystery is hidden in the knowledge base article (78113) that Bernard referenced. Where it says that "Excel 97, however, introduced an optimization that attempts to correct for this problem" [that finite precision binary math sometimes produces correct but unexpected results when subtracting numbers would be equal in decimal representations]. What they did is to assume that if a final subtraction involves two numbers that are equal to at least 15 decimal digits, then Excel will arbitrarily zero the result on the assumption that the non-zero difference is residue from binary approximations. This arbitrary zeroing does not occur if the subtraction is not the last operation (as when the last operation is surrounding parentheses, or within an IF function) since the required assumption may be wrong, in which case the arbitrary zeroing would reduce accuracy that introduced inaccuracy could be magnified by subsequent calculations.

IMHO this "optimization" was a mistake, since it fails to eliminate the situation it was aimed at, and instead makes Excel's math appear inconsistent even to those who do understand the binary issues.

Jerry

ibertram wrote:

Hello folks,

Have you encountered this in your Excel? I am using Excel 2000 SP3.

Let's say you have:
Column A1: 57.16
Column B1: 27.74
Column C1: 84.90

In Column D1, you have this formula: =($A$1+$B$1)-$C$1. Result would be
0
But if you have this formula in column E1: =IF(($A$1+$B$1)-$C$1) = 0,
"it
is zero", "it is not zero"). Result would be "it is not zero". Strange
huh?

It seems that it only happens to this set of number.

Do you have the same result in the other Excel version?

Thank you.

.



Relevant Pages

  • Re: On writing negative zero - with or without sign
    ... I sure hope that a program can represent an exact zero. ... programs represent, manipulate, and produce approximations. ... (which is not what floating point does) ...
    (comp.lang.fortran)
  • Re: On writing negative zero - with or without sign
    ... number of fractional digits, but these digits are all zeroes after ... the values to indicate which side of absolute zero the values lies. ... are two different approximations to zero. ... It's *less* exact. ...
    (comp.lang.fortran)
  • Re: C ++ help!
    ... doubles and I am using a loop to calculate doubles up to an ... at the beginning i get normal approximations and then ... So next line you divide by zero so y is undefined ... Registered Linux User #300464 Machine Id #188886 ...
    (comp.programming)
  • Re: When is zero not zero???
    ... Almost all computer software (including Excel) do binary math following ... result is zero. ... The trailing +0 is needed to make the effects of these approximations ... the result even if the numbers are not equal beyond 15 decimal digits. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: scwewy answers that dont belong
    ... Your explanation then brings up another question in my mind.... ... While I'm familiar with how computers operate, and can get my way around ... numbers involved have exact binary representations, ... approximations (dictated by the IEEE 754 standard that is followed by almost ...
    (microsoft.public.excel.worksheet.functions)