Bug 30813 - Numerical error--#define value differs from declared variable value
Summary: Numerical error--#define value differs from declared variable value
Status: RESOLVED DUPLICATE of bug 323
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.4.5
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-02-15 21:13 UTC by Kevin
Modified: 2021-09-02 07:41 UTC (History)
1 user (show)

See Also:
Host:
Target: i686-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin 2007-02-15 21:13:44 UTC
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
$
Comment 1 Andrew Pinski 2007-02-15 21:23:33 UTC
This works correctly on powerpc-linux-gnu.
Comment 2 Kevin 2007-02-15 21:26:59 UTC
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.


Comment 3 Kevin 2007-02-16 15:29:05 UTC
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.
Comment 4 Andrew Pinski 2021-09-02 07:41:53 UTC
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 ***