4 ms·
There are no values of a where a * a * a differs from a * (a * a), because floating-point multiplication is commutative. With arbitrary numbers a, b, and c, it
by pascal_cuoq 13y ago
There are no values of a where a * a * a differs from a * (a * a), because floating-point multiplication is commutative.
With arbitrary numbers a, b, and c, it would be a different story for a * b * c. Without further knowledge of a, b, c, there would be no particular reason to do the operations in one order or another, but the result of a * b * c and a * (b * c) could definitely differ by one ULP, probably by two in ordinary cases, by more if underflow occurred (but one of the variables would already have to be very small for this to happen).
- deleted 13y ago[deleted]
- 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.