This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Intermediate expression not rounded to float on x86
- To: "'gcc-bugs at gcc dot gnu dot org'" <gcc-bugs at gcc dot gnu dot org>
- Subject: Intermediate expression not rounded to float on x86
- From: "Robison, Arch" <arch dot robison at intel dot com>
- Date: Tue, 30 Jan 2001 07:47:04 -0800
- Cc: "Robison, Arch" <arch dot robison at intel dot com>
Summary:
gcc is not doing strict IEEE arithmetic for x86.
The various IEEE options do not help.
Here's the input program ("t.C"):
----------------------------------------------------------------------------
--
#include <stdio.h>
#include <math.h>
int n = 200;
float f = 0.20000000298023224;
float g;
int main ()
{
int v1, v2;
g = f*n; /* Put product in global float */
v1 = (int) ceil(f*n); /* Compute ceiling of product */
v2 = (int) ceil(g);
if( v1==v2 ) {
printf("Okay: v1=%d=v2\n", v1 );
} else {
printf("Bad: v1=%d!=%d=v2\n", v1, v2 );
}
return 0;
}
----------------------------------------------------------------------------
--
Here's a sample session, which shows the OS version (Red Hat Linux 6.2),
gcc version, options that I used, and the output that I got.
----------------------------------------------------------------------------
--
$ uname -a
Linux brick 2.2.14-5.0smp #1 SMP Tue Mar 7 21:01:40 EST 2000 i686 unknown
$ gcc -v -ieee -ffloat-store t.C -lm
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/cpp -lang-c++ -v -undef
-D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=91 -D__ELF__ -Dunix
-Di386 -D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__i386__
-D__linux__ -D__unix -D__i386 -D__linux -Asystem(posix) -D__EXCEPTIONS
-Asystem(unix) -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__
-D__tune_i386__ -ieee t.C /usr/tmp/ccMGQMOB.ii
GNU CPP version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) (i386
Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
/usr/include/g++-2
/usr/i386-redhat-linux/include
/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include
/usr/include
End of search list.
/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/cc1plus
/usr/tmp/ccMGQMOB.ii -quiet -dumpbase t.cc -version -ffloat-store -o
/usr/tmp/ccCquk2f.s
GNU C++ version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
(i386-redhat-linux) compiled by GNU C version egcs-2.91.66 19990314/Linux
(egcs-1.1.2 release).
as -V -Qy -o /usr/tmp/ccW19es2.o /usr/tmp/ccCquk2f.s
GNU assembler version 2.9.5 (i386-redhat-linux) using BFD version 2.9.5.0.22
/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/collect2 -m elf_i386
-dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o
/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/crtbegin.o
-L/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66
-L/usr/i386-redhat-linux/lib /usr/tmp/ccW19es2.o -lm -lgcc -lc -lgcc
/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/crtend.o /usr/lib/crtn.o
$ a.out
Bad: v1=41!=40=v2
----------------------------------------------------------------------------
----------
Section 6.2.1.4 of the ISO C standard permits excessive precision for values
of
floating-point expressions, but shouldn't -ffloat-store remove the excess
precision?
This is an issue for anyone trying to get reproducible results across IEEE
platforms.
Arch D. Robison Kuck & Associates Inc.
Arch.Robison@intel.com 1906 Fox Drive
217-356-2288 ext. 56 Champaign IL 61820