public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/30813]  New: Numerical error--#define value differs from declared variable value
@ 2007-02-15 21:13 kevin dot glass at pnl dot gov
  2007-02-15 21:23 ` [Bug target/30813] " pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: kevin dot glass at pnl dot gov @ 2007-02-15 21:13 UTC (permalink / raw)
  To: gcc-bugs

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
$


-- 
           Summary: Numerical error--#define value differs from declared
                    variable value
           Product: gcc
           Version: 3.4.5
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kevin dot glass at pnl dot gov


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/30813] Numerical error--#define value differs from declared variable value
  2007-02-15 21:13 [Bug c/30813] New: Numerical error--#define value differs from declared variable value kevin dot glass at pnl dot gov
@ 2007-02-15 21:23 ` pinskia at gcc dot gnu dot org
  2007-02-15 21:27 ` kevin dot glass at pnl dot gov
  2007-02-16 15:29 ` kevin dot glass at pnl dot gov
  2 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-02-15 21:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2007-02-15 21:23 -------
This works correctly on powerpc-linux-gnu.


-- 


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/30813] Numerical error--#define value differs from declared variable value
  2007-02-15 21:13 [Bug c/30813] New: Numerical error--#define value differs from declared variable value kevin dot glass at pnl dot gov
  2007-02-15 21:23 ` [Bug target/30813] " pinskia at gcc dot gnu dot org
@ 2007-02-15 21:27 ` kevin dot glass at pnl dot gov
  2007-02-16 15:29 ` kevin dot glass at pnl dot gov
  2 siblings, 0 replies; 5+ messages in thread
From: kevin dot glass at pnl dot gov @ 2007-02-15 21:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from kevin dot glass at pnl dot gov  2007-02-15 21:26 -------
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.


-- 


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/30813] Numerical error--#define value differs from declared variable value
  2007-02-15 21:13 [Bug c/30813] New: Numerical error--#define value differs from declared variable value kevin dot glass at pnl dot gov
  2007-02-15 21:23 ` [Bug target/30813] " pinskia at gcc dot gnu dot org
  2007-02-15 21:27 ` kevin dot glass at pnl dot gov
@ 2007-02-16 15:29 ` kevin dot glass at pnl dot gov
  2 siblings, 0 replies; 5+ messages in thread
From: kevin dot glass at pnl dot gov @ 2007-02-16 15:29 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from kevin dot glass at pnl dot gov  2007-02-16 15:29 -------
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.


-- 


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/30813] Numerical error--#define value differs from declared variable value
       [not found] <bug-30813-4@http.gcc.gnu.org/bugzilla/>
@ 2021-09-02  7:41 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-02  7:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=30813

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
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 ***

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-09-02  7:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-15 21:13 [Bug c/30813] New: Numerical error--#define value differs from declared variable value kevin dot glass at pnl dot gov
2007-02-15 21:23 ` [Bug target/30813] " pinskia at gcc dot gnu dot org
2007-02-15 21:27 ` kevin dot glass at pnl dot gov
2007-02-16 15:29 ` kevin dot glass at pnl dot gov
     [not found] <bug-30813-4@http.gcc.gnu.org/bugzilla/>
2021-09-02  7:41 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).