floating point operations like addition are not commutative
maybe you meant associative? Floating point addition is commutative: a+b is always equal to b+a for any values of a and b. It is not associative, though: a+(b+c) is in general different to (a+b)+c, think what happens if a is tiny and b,c are huge, for example.
Comments
maybe you meant associative? Floating point addition is commutative: a+b is always equal to b+a for any values of a and b. It is not associative, though: a+(b+c) is in general different to (a+b)+c, think what happens if a is tiny and b,c are huge, for example.
Sorry, yes, I meant associative. Thanks for the important correction.
To think that I used to do this for a living...
How is that any different? 1+(2+3) = 6
(1+2)+3 = 6
0.000001+(200000+300000) = 500000.000001
(0.000001+200000)+300000 = 500000.000001
You need to take it a step further, since e.g. 64-bit floats have a ton of mantissa bits.
Here's an example in python3.
take b and c with opposite signs