This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Floating point trouble wit x86's extended precision


[Apologies if you've received this twice, I screwed up the first time]

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
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]