Thread Links Date Links
Thread Prev Thread Next Thread Index Date Prev Date Next Date Index

Re: Conflicts between C standard and 754-2008



On 2011-01-06 15:05:35 +0200, Hossam A. H. Fahmy wrote:
> 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.

No, you're also using the associativity here, because a+b+c is
interpreted unambiguously as (a+b)+c. And from (a+b)+c to (a+c)+b,
you're not using the commutativity only, but a succession of
commutativity and associativity transformations.

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Arénaire project (LIP, ENS-Lyon)