This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
Re: optimization/9654: extra-precision fp comparisons are less accurate
- From: <rearnsha at gcc dot gnu dot org>
- To: nobody at gcc dot gnu dot org
- Cc: gcc-prs at gcc dot gnu dot org,
- Date: 12 Feb 2003 17:56:00 -0000
- Subject: Re: optimization/9654: extra-precision fp comparisons are less accurate
- Reply-to: <rearnsha at gcc dot gnu dot org>
The following reply was made to PR optimization/9654; it has been noted by GNATS.
From: <rearnsha@gcc.gnu.org>
To: richard@wetafx.co.nz, gcc-gnats@gcc.gnu.org, gcc-bugs@gcc.gnu.org
Cc:
Subject: Re: optimization/9654: extra-precision fp comparisons are less accurate
Date: Wed, 12 Feb 2003 17:49:17 +0000
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.