Remix.run Logo
wtallis 10 hours ago

"a+b+c" doesn't describe a unique evaluation order. You need some parentheses to disambiguate which changes are due to associativity vs commutativity. a+(b+c)=(c+b)+a should be true of floating point numbers, due to commutativity. a+(b+c)=(a+b)+c may fail due to the lack of associativity.

adastra22 10 hours ago | parent [-]

It is not, due to precision. Consider a=1.00000, b=-0.99999, and c=0.00000582618.

jcranmer 9 hours ago | parent | next [-]

No, the two evaluations will give you exactly the same result: https://play.rust-lang.org/?version=stable&mode=debug&editio...

IEEE 754 operations are nonassociative, but they are commutative (at least if you ignore the effect of NaN payloads).

dbdr an hour ago | parent [-]

Is there a case involving NaN where they are not commutative? Do you mean getting a different bit-level representation of NaN?

Remnant44 8 minutes ago | parent [-]

In practical use for simd, various min/max operations. On Intel at least, they propagate nan or not based on operand order

zygentoma 10 hours ago | parent | prev | next [-]

You still need to specify an evaluation order …

immibis 9 hours ago | parent | prev [-]

Does (1.00000+-0.99999)+0.00000582618 != 0.00000582618+(-0.99999+1.00000) ? This would disprove commutativity. But I think they're equal.