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

*To*: stds-754 <stds-754@xxxxxxxxxxxxxxxxx>*Subject*: Re: Conflicts between C standard and 754-2008*From*: "Hossam A. H. Fahmy" <hfahmy@xxxxxxxxxxxxxxxxxxxxxxx>*Date*: Thu, 6 Jan 2011 13:39:59 +0200*Cc*: stds-1788 <stds-1788@xxxxxxxxxxxxxxxxx>*In-reply-to*: <20110104061307.D9EE78C01D4@xxxxxxxxx>*List-help*: <http://listserv.ieee.org/cgi-bin/wa?LIST=STDS-754>, <mailto:LISTSERV@LISTSERV.IEEE.ORG?body=INFO%20STDS-754>*List-owner*: <mailto:STDS-754-request@LISTSERV.IEEE.ORG>*List-subscribe*: <mailto:STDS-754-subscribe-request@LISTSERV.IEEE.ORG>*List-unsubscribe*: <mailto:STDS-754-unsubscribe-request@LISTSERV.IEEE.ORG>*References*: <201101012242.p01MgJsb018386@xxxxxxxxxxxxxxxxxxx> <Prayer.1.3.3.1101021513430.4637@xxxxxxxxxxxxxxxxxxxxxx> <20110103211346.GA19559@xxxxxxxxxxxxxxx> <4D22AD01.6030000@xxxxxxxxxxxxx> <20110104061307.D9EE78C01D4@xxxxxxxxx>*Sender*: stds-754@xxxxxxxx

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

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1539.pdf)

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,

#include<stdio.h>

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

Â z-y+x=100

Â z+x-y=0

Â x-y+z=0

Â x+z-y=0

Â-y+z+x=100

Â-y+x+z=0

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

anyone?

--

Hossam A. H. Fahmy

Associate Professor

Electronics and Communications Engineering

Cairo University

Egypt

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

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1539.pdf)

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,

#include<stdio.h>

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

Â z-y+x=100

Â z+x-y=0

Â x-y+z=0

Â x+z-y=0

Â-y+z+x=100

Â-y+x+z=0

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

anyone?

--

Hossam A. H. Fahmy

Associate Professor

Electronics and Communications Engineering

Cairo University

Egypt

**Follow-Ups**:**Re: Conflicts between C standard and 754-2008***From:*JÃrgen Wolff von Gudenberg

**Re: Conflicts between C standard and 754-2008***From:*David Monniaux

**References**:**Re: Conflicts between C standard and 754-2008***From:*Vincent Lefevre

**Re: Conflicts between C standard and 754-2008***From:*Dan Zuras IEEE

- Prev by Date:
**Re: Conflicts between C standard and 754-2008** - Next by Date:
**Re: Conflicts between C standard and 754-2008** - Previous by thread:
**Re: Conflicts between C standard and 754-2008** - Next by thread:
**Re: Conflicts between C standard and 754-2008** - Index(es):