2011/1/6 David Monniaux <David.Monniaux@xxxxxxx>
On 01/06/2011 12:39 PM, Hossam A. H. Fahmy wrote:As far as I understand, you are referring to associativity, not
> 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,
(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
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
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
Electronics and Communications Engineering