[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Conflicts between C standard and 754-2008

754 and 1788 members,

I followed the steps of Michel and tried to see if there are any other
issues with the C standard that conflict with 754-2008. I used the links
provided by Fred Tydeman on the current versions of the standard.
(http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf and

I found that on page 452 of document n1256 (also on page 511 of n1539)
within the annex on floating point, C allows the transformations

x - y = x + (-y) = (-y) + x

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,


int main (void)
float x=1e2, y=1e30, z=1e30;

printf("\n x=%g, y=%g, z=%g", x, y, z);
printf("\n z-y+x=%g\n", z-y+x);
printf("\n z+x-y=%g\n", z+x-y);
printf("\n x-y+z=%g\n", x-y+z);
printf("\n x+z-y=%g\n", x+z-y);
printf("\n -y+z+x=%g\n", -y+z+x);
printf("\n -y+x+z=%g\n", -y+x+z);

when compiled with gcc without any optimizations yields:

Âx=100, y=1e+30, z=1e+30






which is the expected behavior from a 754-2008 compliant system.
However, if the compiler used the transformation mentioned by the C
standard the results would not be the same.

Is my understanding correct and this is indeed a conflict? Comments
Hossam A. H. Fahmy
Associate Professor
Electronics and Communications Engineering
Cairo University

754 | revision | FAQ | references | list archive