Thread: Accuracy
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Joe User[_2_] Joe User[_2_] is offline
external usenet poster
 
Posts: 905
Default Accuracy

"Ad Pronk" wrote:
Using Excel 2003 I "discover" a strange thing. Placing brackets
around a term introduces an inaccuracy. Is this normal?


Yes, to some degree. It is questionable whether the parentheses introduce
an "inaccuracy" per se. But they certainly can change the result.

Since you neglected to include details (klunk!), I cannot reproduce and
discuss exactly what you are seeing.

But generally, adding parentheses to expressions can change the order of
evaluation; the same is true by simply reordering terms. And that can
change the final outcome in some cases, depending on the numbers involved.

Here is a simple example:

A1: =2226-123.36-39.34
A2: =2226-(123.36+39.34)
A3: =-123.36-39.34+2226

All results are displayed as 2063.3 in General format. In fact, they even
appear identical if you format as Scientific with 14 decimal places, the
most number of significant digits (15) that Excel will format.

Moreover, =A1=A2 returns TRUE, and =A1-A2 returns exactly zero.

But =A1-A2=0 returns FALSE, and =(A1-A2) returns about -4.547E-13.

Note that the latter is not an "inaccuracy". In fact, it is the more
accurate difference between the values in A1 and A2.

Not surprisingly, A3 has exactly the same result as A2, even without
additional parentheses.

The primary issue is the way that Excel (and most applications) store
numbers and perform arithmetic by default. It is called binary floating
point -- more specifically, IEEE-754 double-precision floating point.

A secondary issue is various Excel heuristics (algorithms), which are
intended to hide some of the anomalies arise with floating-point arithmetic.
Although well-intentioned, the heuristics are half-baked, often creating
even stranger results. This is the reason why A1=A2 is return TRUE, but
A1-A2=0 is FALSE above.

The work-around is to use ROUND prolifically, but prudently. That is,
explicitly round results of most arithmetic expressions that might result in
fractional digits.

Another common alternative is to use expressions of the form ABS(A1-A2)<0.01
when comparing such numbers. But that has obvious limited application, and
it can result in surprises because 0.01 cannot be represented exactly in
binary floating point.

Alternatively, you might consider using the "Precision as displayed"
calculation option. I deprecate the use of that feature because of its
uncontrolled pervasive effect. If you choose to experiment with it, you
should first make a copy of the Excel workbook file. Some changes cause by
setting PAD are irreversible.


----- original message -----

"Ad Pronk" wrote in message
...
Using Excel 2003 I "discover" a strange thing. Placing brackets around a
term
introduces an inaccuracy. Is this normal?
1-(1/cos(x)*cos(a.t+x) is nil for t=0 as it should be. But I use this term
in a series, so I have to place brackets around the term:
(1-(1/cos(x)*cos(a.t+x))
And surprisingly for t=0 I get the answer 1.1 E(-14).
It's small but I expect at least a value below E(-22) or 0

Reactions are welcomed
Ad Pronk