2011/1/6 David Monniaux
<David.Monniaux@xxxxxxx>
On 01/06/2011 12:39 PM, Hossam A. H. Fahmy wrote:
> I am a bit troubled by this since it means that C assumes that FP
> addition is commutative in general which is not true. It is specifically
> wrong if applied on more than two terms. For example,
As far as I understand, you are referring to associativity, not
commutativity:
(a + b) + c == a + (b + c)
Commutativity is just the permission to swap the two operands to a +.
Yes, commutativity is the swapping of the terms around the operator but in the examples:
x=100, y=1e+30, z=1e+30
z-y+x=100
z+x-y=0
and without any parenthesis I assumed that the evaluation will always proceed from left to right and I swapped the second and third term. So we are getting:
(z-y)+x = 100
and
(z+x)-y=0
which is as expected in 754. However, C says that (-y)+x is the same as x+(-y) so an optimizing compiler can assume that the two statements z-y+x and z+x-y (just commutativity on the 2nd and 3rd term) are equivalent which they are not under 754.
Does this explain better the point of conflict that I imagine?
--
Hossam A. H. Fahmy
Associate Professor
Electronics and Communications Engineering
Cairo University
Egypt