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
[parent not found: <bug-30813-4@http.gcc.gnu.org/bugzilla/>]

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).