This is the mail archive of the gcc@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]

Re: optimization problem with 1.0.3


>> concerned, f is no longer even deterministic.  Isn't this a bad thing?
>> Shouldn't the code generated by gcc prevent this kind of thing from
>> happening?
>
>I don't see why.  how about a diagnostic message that says
>"warning: you can never compare different floats/doubles with == or !=,
>even if you think they're the same value."

When I ran into the source of my problems originally, I was not
trying to use == or != .  The example I had originally
asked about was rather confused--- I didn't really understand the
nature of the problem so I couldn't illustrate it very well.  But
now look at this:


beefalo% cat fp_problem2_p.c 
#include <stdio.h>

double f(double x)
{
  return x/3.0;
}

int main()
{
  int count;
  double x = 1.0, y = 1.0;

  if(f(x) < f(y)) {
    printf("f(x) is less than f(y)\n");
    if(f(y) < f(x)) {
      printf("AND\nf(y) is less than f(x)\n");
    }
  }

  return 0;
}
beefalo% gcc fp_problem2_p.c
beefalo% a.out
f(x) is less than f(y)
AND
f(y) is less than f(x)



Surely _this_ is bad?


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