This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/26941] New: float optimization bug
- From: "zengpan at goldhuman dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 30 Mar 2006 13:10:57 -0000
- Subject: [Bug c/26941] New: float optimization bug
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
[root@FedoraCore5 tmp]# cat a.c
#include <stdio.h>
float Q_rsqrt(float number)
{
long i;
float x2, y;
float threehalfs = 1.5f;
x2 = number * 0.5f;
y = number;
i = *(long *)&y;
i = 0x5f3759df-(i>>1);
y = *(float *)&i;
y = y * (threehalfs -(x2 *y *y));
y = y *(threehalfs - (x2 *y *y));
return y;
}
int main()
{
printf("%f\n", Q_rsqrt(305.0f));
return 0;
}
[root@FedoraCore5 tmp]# gcc a.c
[root@FedoraCore5 tmp]# ./a.out
0.057260
[root@FedoraCore5 tmp]# gcc -O2 a.c
[root@FedoraCore5 tmp]# ./a.out
0.000000
[root@FedoraCore5 tmp]# gcc -v
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--enable-checking
=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-libgcj-multifile
--enable-languages=c,c++,objc,obj-c++,java,
fortran,ada --enable-java-awt=gtk --disable-dssi
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic
--host=i386-redhat-linux
Thread model: posix
gcc version 4.1.0 20060304 (Red Hat 4.1.0-3)
--
Summary: float optimization bug
Product: gcc
Version: 4.1.0
Status: UNCONFIRMED
Severity: critical
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: zengpan at goldhuman dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26941