public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [BUG] GCC 4.1 bug - Optimization breaks variables of type double
@ 2007-11-15 17:12 Le Thanh Trung
  0 siblings, 0 replies; only message in thread
From: Le Thanh Trung @ 2007-11-15 17:12 UTC (permalink / raw)
  To: gcc-bugs

Hi,

When I compile my program without optimization (-O2 or -O3), it works
normally. However when I compile the code with -O2 or -O3 (GCC version
4.1), my program output wrong data. In addition, I did not see this
problem when I used GCC 3.4.6.

Information regarding my GCC:
OS: Centos 5  (a clone of Redhat Enterprise 5)
GCC: 4.1.1 20070105 (Red Hat 4.1.1-52)

Command:
   gcc -g -Wall gensvmparams.c -lm -o gensvmparams
   gcc -g -Wall -O2 gensvmparams -c -lm -o gensvmparams
   
My code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
  double g = pow(2, -7);
  double c = 2;
  double cc = 1;
  double gg = -7;
  double cMax;
  cMax = pow(2,5);
  cMax = cMax + 0.000001;
  double gMax;
  gMax = pow(2,-3);
  gMax = gMax + 0.000001;

  while (c < cMax)  //gcc -O2 change the cMax to something different
than 32
  {
    gg = -7;
    g = pow(2, -7);
    while (g < gMax)
    {
      printf("5 %lf %lf\n", c, g);
      gg = gg + 0.25; 
      g = pow(2, gg);
    }
    cc = cc + 0.25;
    c = pow(2, cc);
  }
  return 0;
}

P.S: When I add "volatile" to the declaration of cMax and gMax, my
program works correctly for all cases.

Thanks,
Regards,
Le Thanh Trung



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-11-15 17:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-15 17:12 [BUG] GCC 4.1 bug - Optimization breaks variables of type double Le Thanh Trung

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