3 ms·
> floating-point multiplication is commutative. It's not, except in the special case of one and the same number.
by acqq 13y ago
> floating-point multiplication is commutative.
It's not, except in the special case of one and the same number.
- pascal_cuoq 13y agoYou have to be kidding. Otherwise, read up on the definition of “commutative” here: http://en.wikipedia.org/wiki/Commutative_property http://en.wikipedia.org/wiki/Commutative_property Look for the first occurrence of the word “commutative” in this page: http://en.wikipedia.org/wiki/Floating_point http://en.wikipedia.org/wiki/Floating_point But remember, if both the Wikipedia editors and I are wrong, you only need to produce one pair of operands a and b such that a * b does not produce not the same result(1) as b * a to be vindicated. (1) I suggest we consider all NaN values to be “the same result” for the purpose of this challenge.
- acqq 13y agoYou're right of course. I was thinking about associtivity, not seeing what's really written. Sorry. I didn't expect discussing commutativity in the context (it's the non-associativity that doesn't allow all the "automatic" optimizations expected by some) where the formula in the same sentence is with three elements and the different order of computation. Which doesn't change the fact that I've made an error.
- ska 13y agoNo, fp (IEEE-745) + and * are both commutative. They aren't associative or distributive in general.