other/5574: "http://ego.uwaterloo.ca/SpamGate?ip=216.94.64Off by two error produced by gcc -o test sqr.c -lm

sayle@gcc.gnu.org sayle@gcc.gnu.org
Fri Aug 2 20:38:00 GMT 2002


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



More information about the Gcc-bugs mailing list