Re: Q: When 0 <> 0 ?



splever@xxxxxxxxx wrote:

> Example: Place the following values in a column and sum them.
> -116.33
> 98.53
> 17.80
> 0
> =============
> Excel returns: 0.0000000000000035527136788005
> [....]
> If you remove 0 from the list ( or put it in a different
> place in the list, the proper result, 0 is returned.

I do not think that any of the answers so far address
your point, namely: the result is order-sensitive. Even
taking the IEEE floating-point format into account, it
does seem odd that adding zero at different times yields
different results.

I think the answer goes beyond the IEEE FP format to the
typical IEEE FP implementation within the CPU or chipset.
As I recall, for Intel chips, the internal FP format is
twice as wide as the storage. Programmers can rely on
the internal FP registers explicitly -- and compilers
can use them in various ways, depending on the complexity
of the computation. This can lead to different truncation
errors, depending on when the wider internal FP results
are copied into memory or general-purpose FP registers.

> I have a workaround, but would love to see comments...

Since the behavior is relatively unpredictable and
potential non-portable across processors, it would be
better to live with the reality and use prudent numerical
methodologies to deal with it.

For example, never compare a floating-point result of a
computation with zero, and never compare two FP results
for equality. Always compare with some "delta", the
size of which depends on your requirements. For example:
=IF(ABS(A1-A2) < 1E-6, "equal", "not equal").

Alternatively, when feasible, only use integral
floating-point values, using ROUND() for FP results.

Of course, that is easier said than done. Most of us
dispense with the "prudent" methods and hope for the
best.

.



Relevant Pages

  • Re: cobol data format!!! urgent!!!
    ... misunderstood what "conformance to a standard" means. ... Cobol people 'know' binary floating-point is ... The quotation above is from IEEE 754. ... same as the IBM System/390 format which isn't the same as the Unisys MCP ...
    (comp.lang.cobol)
  • RfD: IEEE-FP 0.5.2
    ... the default format can be any IEEE binary ... restored to *nearly* the same as DPANS94 ... IEEE comparisons reworked ... This is a proposal for an optional Forth 200x word set, ...
    (comp.lang.forth)
  • Re: RfD: IEEE-FP
    ... although not given a name in IEEE. ... >> if the input load is too large for the default format. ... Conversion operations for binary formats 5.4.3.0 ... >> roundToIntegralExact ...
    (comp.lang.forth)
  • Re: Testing if a real is NaN
    ... Note also that they apply *only* to IEEE single and double format. ... I'm not sure that the IEEE standard specifies how infinities and NaNs are ... > usenet postings to find compensation for whatever went wrong in their ...
    (comp.lang.fortran)
  • Re: Leading zeroes, text/numbers, import/export
    ... >If I want to do arithmetic, use a numeric format. ... >> We import into Excel and sometimes later export to ... >> can compare them from one list or sheet to another, ... Then, when comparing to other lists or exporting, ...
    (microsoft.public.excel.misc)