Floating point trouble wit x86's extended precision

Roger Sayle roger@eyesopen.com
Thu Aug 21 05:40:00 GMT 2003


Hi Volker,
> I wanted to construct a very extreme case where rounding leads to
> unexpected behaviour and came up with the following example:
>
> ============================================
> int main()
> {
>   double x = sqrt(2.0);
>   volatile double y = x;
>   if (x!=y) printf("Uh oh!\n");
>   return 0;
> }
> ============================================
>
> Compiling this with GCC 3.3.1 and using -O2 I get the output:
> "Uh oh!"

It should probably be pointed out that this may be a poor example
for GCC's WWW pages, as this particular test case is fixed in 3.4!
Mainline CVS evaluates sqrt(2.0) at compile-time and correctly
rounds it to double precision.

Perhaps, using sin(0.5) instead, will have a longer life-time...

Roger
--



More information about the Gcc mailing list