I've used a #define to set a value, I've set a declared variable to the same text value and I've set a second declared variable to the #define value. The declared values are the same, the #define value differs. If this were a simple round off error, all three values should be the same. As they are not the same, the #define has a different value. I think the #define might have access to all of the guard bits in the FPU whereas the declared values are truncated. Also, please note, this problem does not happen with gcc 2.9.2 and I'm running on Red Hat Linux ============================================================================== cat prec.c ============================================================================== #include <stdio.h> #define VALUE 1e-4 int main() { double v = 1.0; double a = 1e-4; double b = VALUE; printf("a = %e\n", a); printf("def/var - 1 = %e, var/def - 1 = %e\n", (VALUE*VALUE)/(a*a) - v, (a*a)/(VALUE*VALUE) - v); printf("def/var2 - 1 = %e, var2/def - 1 = %e\n", (VALUE*VALUE)/(b*b) - v, (b*b)/(VALUE*VALUE) - v); printf("var/var - 1 = %e, def/def - 1 = %e\n", (a*a)/(a*a) - v, (VALUE*VALUE)/(VALUE*VALUE) - v); printf("var2/var1 - 1 = %e, var2/var2 - 1 = %e\n", (b*b)/(a*a) - v, (b*b)/(b*b) - v); } ======================================================================================== $ gcc prec.c $ ./a.out a = 1.000000e-04 def/var - 1 = -7.486416e-17, var/def - 1 = 7.491837e-17 def/var2 - 1 = -7.486416e-17, var2/def - 1 = 7.491837e-17 var/var - 1 = 0.000000e+00, def/def - 1 = 0.000000e+00 var2/var1 - 1 = 0.000000e+00, var2/var2 - 1 = 0.000000e+00 $
This works correctly on powerpc-linux-gnu.
Subject: RE: Numerical error--#define value differs from declared variable value I ran on a 64-bit Itanium running Red Hat linux, I'm not sure which version. -----Original Message----- From: pinskia at gcc dot gnu dot org [mailto:gcc-bugzilla@gcc.gnu.org] Sent: Thursday, February 15, 2007 1:24 PM To: Glass, Kevin A Subject: [Bug target/30813] Numerical error--#define value differs from declared variable value ------- Comment #1 from pinskia at gcc dot gnu dot org 2007-02-15 21:23 ------- This works correctly on powerpc-linux-gnu.
I ran this on a Pentium III and a Pentium IV using gcc 3.4.5 and gcc 4.01(?). These produced incorrect results. I also ran them on an itanium using an older gcc (2.9.2) in these cases, it produced correct results.
ok, this is really PR 323. With -std=c90 or -std=c99, it provides the correct thing for x86 (but note it is not 0 really). Also you could use -mfpmath=sse these days. *** This bug has been marked as a duplicate of bug 323 ***