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]

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


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.


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