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]

[Bug target/52593] Builtin sqrt on x86 is not correctly rounded


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52593

--- Comment #2 from Rich Felker <bugdal at aerifal dot cx> 2012-03-15 16:37:25 UTC ---
Tested with gcc 4.6.2.

#include <stdio.h>
#include <math.h>
int main()
{
    volatile double x = 0x1.fffffffffffffp-1;
    volatile double y = sqrt(x);
    printf("%a\n", y);
}

Compile with -O2 -ffloat-store, and this program gives an output of 0x1p+0,
rather than the correct output of 0x1.fffffffffffffp-1. Unfortunately it's
impossible to get the correct output with glibc's -lm version of sqrt either
since it has the exact same bug. But you can look at the generated assembly
with and without -fno-builtin-sqrt and see that the version with builtin sqrt
is wrong (using the fsqrt opcode directly).


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