This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

optimization/10825: GCC 2.3.2 cannot compare two double


>Number:         10825
>Category:       optimization
>Synopsis:       GCC 2.3.2 cannot compare two double
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Fri May 16 18:36:02 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Franck Le Thiec
>Release:        3.2.3
>Organization:
>Environment:
i386-linux 2.4.17
>Description:
in a loop a multiple of M_PI is put into two variables,
one is an array of double allocated by malloc
the other is a double.
they compare equal when using gcc with options "-lm" or "-O1 -lm"
they compare different when using gcc with "-O2 -lm" or "-O3 -lm" or "-O4 -lm"
>How-To-Repeat:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(int argc, char **argv)
{
  double *a1,a2;
  int i;

  a1 = (double*)malloc(sizeof(double));
  a1[0]=a2=0.0;

  for(i=1;i<15;i++)
    { /*if we loop until 13 no problem!*/
      a1[0] += M_PI;
      a2 += M_PI;
    }

  printf("%.50f\n%.50f\n",a1[0], a2);
  if (a1[0]==a2)
    printf("equal\n");
  else
    printf("different\n");

  free(a1);
}
>Fix:
no known fixes !
>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]