public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* other/5574: "http://ego.uwaterloo.ca/SpamGate?ip=216.94.64Off by two error produced by gcc -o test sqr.c -lm
@ 2002-02-01 11:16 murph
0 siblings, 0 replies; 2+ messages in thread
From: murph @ 2002-02-01 11:16 UTC (permalink / raw)
To: gcc-gnats
>Number: 5574
>Category: other
>Synopsis: "http://ego.uwaterloo.ca/SpamGate?ip=216.94.64Off by two error produced by gcc -o test sqr.c -lm
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Feb 01 11:16:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: murph@winface.com
>Release: Most gcc 2.9X
>Organization:
>Environment:
Most Linux on Intel systems.
>Description:
The program:
#include stdio.h
#include math.h;
main()
{
register i;
double f=0.0;
double sqrt();
for(i=0;i<=1000000000;i++)
{
f+=sqrt( (double) i);
}
printf("Finished %20.14f\n",f);
}
compiled on linux as:
gcc -o test sqr.c -lm
typically produces:
21081851083598.38281250000000
but compiling as:
gcc -march=i686 -O3 -lm -o test sqr.c
yeilds: 21081851083600.38281250000000
which is closer to the right answer by exactly 2.0.
See: http://www.winface.com/sqrc_results.html for more info.
>How-To-Repeat:
See: http://www.winface.com/sqrc_results.html for more info.
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: other/5574: "http://ego.uwaterloo.ca/SpamGate?ip=216.94.64Off by two error produced by gcc -o test sqr.c -lm
@ 2002-08-02 20:38 sayle
0 siblings, 0 replies; 2+ messages in thread
From: sayle @ 2002-08-02 20:38 UTC (permalink / raw)
To: gcc-bugs, gcc-prs, murph, nobody
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-08-03 3:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-01 11:16 other/5574: "http://ego.uwaterloo.ca/SpamGate?ip=216.94.64Off by two error produced by gcc -o test sqr.c -lm murph
2002-08-02 20:38 sayle
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).