This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/52593] Builtin sqrt on x86 is not correctly rounded
- From: "bugdal at aerifal dot cx" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 15 Mar 2012 16:37:25 +0000
- Subject: [Bug target/52593] Builtin sqrt on x86 is not correctly rounded
- Auto-submitted: auto-generated
- References: <bug-52593-4@http.gcc.gnu.org/bugzilla/>
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).