From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14660 invoked by alias); 3 Aug 2002 03:38:53 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 14639 invoked by uid 61); 3 Aug 2002 03:38:52 -0000 Date: Fri, 02 Aug 2002 20:38:00 -0000 Message-ID: <20020803033852.14638.qmail@sources.redhat.com> To: gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, murph@winface.com, nobody@gcc.gnu.org From: sayle@gcc.gnu.org Reply-To: sayle@gcc.gnu.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, murph@winface.com, nobody@gcc.gnu.org, gcc-gnats@gcc.gnu.org Subject: Re: other/5574: "http://ego.uwaterloo.ca/SpamGate?ip=216.94.64Off by two error produced by gcc -o test sqr.c -lm X-SW-Source: 2002-08/txt/msg00047.txt.bz2 List-Id: 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