optimization/9654: extra-precision fp comparisons are less accurate

rearnsha@gcc.gnu.org rearnsha@gcc.gnu.org
Wed Feb 12 17:51:00 GMT 2003


http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=9654

I think it's very dangerous to assume that

acos(something-nearly-equal-to-1)

won't return 0, or, more importantly

sin (acos(something-nearly-equal-to-1)

won't.

A simple test after the assignment of o would suffice to avoid this 
problem, eg:

#include <math.h>

double s(double t) throw()
{
   double d = 0.75+t;
   double o = d < 1.0 ? acos(d) : 1.0/67108864.0;
   if (o == 0.0) o = 1.0 / 67108864.0;
   return sin(o*0.5)/sin(o);
}

int main(void)
{
   return isnan(s(0.25-1.0/18014398509481984.0));
}

If you are really paranoid, then a range check on small o and applying 
L'Hoptial's Rule might not be a bad idea.

I really don't think you'd like the alternatives to -ffloat-store any 
more than you like -ffloat-store.



More information about the Gcc-bugs mailing list