in reply to strange result for a simple addition ??

Marcel--

Many floating point numbers don't have an exact binary floating point representation. So after a few operations, it's normal to get odd digits a few places to the right.

For example, 1/3 doesn't have an exact decimal representation. If you truncate to 3 digits past the decimal, and subtract 1/3 three times from one, you'd also have an odd value:

1.000 - 0.333 = 0.667 0.667 - 0.333 = 0.334 0.334 - 0.333 = 0.001

--roboticus

Replies are listed 'Best First'.
Re^2: strange result for a simple addition ??
by GrandFather (Saint) on Aug 25, 2006 at 20:22 UTC

    Actually 0.1 decimal can't be represented as a finite binary fraction so suffers from rounding errors and the accumulation of rounding errors that OP is seeing.


    DWIM is Perl's answer to Gödel
      Right...that's the situation I was giving an example of.

      --roboticus