lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Pantelis Kavallieratos <kavallieratos@gmail.com> writes:

> one would expect that b=1-(1-a) leads to b=a

Huh?  Since when does the associative law hold with floating point
arithmetic?

With _very_ well picked rounding and arithmetic, you can get to the
point where (evaluated from left to right)

a+b-b = a+b-b+b-b

(namely you don't lose _additional_ precision when trying the same
"neutral" operation a second time, having rounded to a more stable
starting point the first time round) but it is not possible to arrive at

a+b-b = a

since the whole point of floating point arithmetic is the acceptance of
small losses of precision during operations.

-- 
David Kastrup