[EMAIL PROTECTED] 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;
}
[EMAIL PROTECTED] tmp]# gcc a.c
[EMAIL PROTECTED] tmp]# ./a.out
0.057260
[EMAIL PROTECTED] tmp]# gcc -O2 a.c
[EMAIL PROTECTED] tmp]# ./a.out
0.000000
[EMAIL PROTECTED] 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

Reply via email to