On Sat, Aug 22 2015, Michael Orlitzky wrote:

> On 08/22/2015 09:42 AM, R0b0t1 wrote:
>> https://en.wikipedia.org/wiki/Round-off_error
>> https://en.wikipedia.org/wiki/Machine_epsilon
>> 
>> Either add a tolerance (a - b <= t) or compare them as strings as
>> you've been doing.
>> 
>
> You probably want |a - b| <= t there =)
>
> But... that can cause problems too. If your numbers are small enough,
> you can wind up with infinity or NaN (not a number) and then your
> comparisons will go berserk.
>
> Floating point addition isn't even commutative:
>
>   > 0.1 + 0.2 + 0.3
>   0.6000000000000001
>   > 0.1 + (0.2 + 0.3)
>   0.6

That demonstrates non-associativity.  I believe floating point is
commutative: a+b = b+a

> Better to avoid that quagmire entirely if you can. Use fixed point
> arithmetic, arbitrary precision, or even rational numbers if you can get
> away with it.

Agreed.
allan

Reply via email to