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

[Bug middle-end/20674] unexpected result from floating compare


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-03-28 22:34 -------
If you write the function like so:
enum myRC doSomeMath
(
 int i1,
 float *f1,
 float* f2,
 float* f3,
 float* f4
)
{
  int i;
  float f5=0.0;
  float f6=0.0;
  float f7=0.0;

  for(i=0; i<i1global; i++){
    f5+=f1[i]*f1[i];
    f6+=f2global[i1][i]*f2global[i1][i];
    f7+=f1[i]*f2global[i1][i];
  }
  *f2=sqrt(f5);
  *f3=sqrt(f6);
  *f4=f7/(*f2* *f3);

  if((*f4>=-1.0)&&(*f4<=1.0))return(mySuccess);
  if((*f4>1.0)&&(*f4<1.000001)){
    *f4=1.0;
    return(mySuccess);
  }
  if((*f4<-1.0)&&(*f4>-1.000001)){
    *f4=-1.0;
    return(mySuccess);
  }
  if ( chkWithEqual == 1 ) {
    if((*f4>=1.0)&&(*f4<1.000001)){
      *f4=1.0;
      return(mySuccess);
    }
    if((*f4<=-1.0)&&(*f4>-1.000001)){
      *f4=-1.0;
      return(mySuccess);
    }
  }
  printf("%f is out of range -1.0 to 1.0\n",*f4);
  return(myFailure);
}

You still get the fail even with the C front-end in 3.4.0.

Note this does not fail in 4.0.0 and above (though there might be a way get a simlar failure if you have 
time to fiind one.  But I think this is still a precission problem.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c++                         |middle-end
           Keywords|                            |wrong-code


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


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