This is the mail archive of the gcc-bugs@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: other/5574: "http://ego.uwaterloo.ca/SpamGate?ip=216.94.64Off by two error produced by gcc -o test sqr.c -lm


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


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