casting a negative _int128_t value to a float or double rounds the resulting
floating point number to the nearest multiple of 2048.

the following C program demonstrates which I compiled with the compile string
"gcc":

int main()
{
        __int128_t x = -1025;
        double f = x;
        return f < -1500.0;
}

I would expect the exit code of the program to be 0. f should get set to
-1025.0, which is not < -1500.0.

However when I compile and run this the exit code is 1.

Further examination shows that f gets the following values:
    0.0 for x in the range -1024 to 0
-2048.0 for x in the range -3060 to -1025
    ...etc...

When x is positive f gets set to the expected (the same) value.

"gcc -v" output:

Using built-in specs.
Target: x86_64-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-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk
--disable-dssi --enable-plugin
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre
--enable-libgcj-multifile --enable-java-maintainer-mode
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar --with-cpu=generic
--host=x86_64-redhat-linux
Thread model: posix
gcc version 4.1.2 20070925 (Red Hat 4.1.2-33)


-- 
           Summary: casting negative __int128_t to float/double rounds to
                    nearest multiple of 2048
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: james at albanarts dot com
 GCC build triplet: x86_64-redhat-linux
  GCC host triplet: x86_64-redhat-linux
GCC target triplet: x86_64-redhat-linux


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

Reply via email to