This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: other/5574: "http://ego.uwaterloo.ca/SpamGate?ip=216.94.64Off by two error produced by gcc -o test sqr.c -lm
- From: sayle at gcc dot gnu dot org
- To: gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, murph at winface dot com, nobody at gcc dot gnu dot org
- Date: 3 Aug 2002 03:38:52 -0000
- Subject: Re: other/5574: "http://ego.uwaterloo.ca/SpamGate?ip=216.94.64Off by two error produced by gcc -o test sqr.c -lm
- Reply-to: sayle at gcc dot gnu dot org, gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, murph at winface dot com, nobody at gcc dot gnu dot org, gcc-gnats at gcc dot gnu dot org
Synopsis: "http://ego.uwaterloo.ca/SpamGate?ip=216.94.64Off by two error produced by gcc -o test sqr.c -lm
State-Changed-From-To: open->closed
State-Changed-By: sayle
State-Changed-When: Fri Aug 2 20:38:52 2002
State-Changed-Why:
This is a well known issue with floating point calculations.
See the section of "non-bugs" section of GCC's bugs WWW page
http://gcc.gnu.org/bugs.html#nonbugs, particularly the
paragraph entitled "Problems with floating point computations".
The issue is "real" values cannot be represented precisely
in the "floating point" representations used by current
computer hardware. In your test case, when compiling
without optimizations the program calls the system sqrt
routine, and rounds both the sqrt result and the result
of each addition to 64 bit precision by writing the results
to memory on each iteration. With optimizations, the
program uses the Pentium's fsqrt instruction and accumulates
the result in floating point registers, both to 80 bits of
precision.
For more information, see the Goldberg paper linked to from
the above URL, and the documentation of the "-ffloat-store"
command line option in the GCC manual:
http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#Optimize%20Options
I hope this explains the odd behaviour.
Roger
--
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5574