This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: weird optimization in sin+cos, x86 backend
On Feb 5, 2012, at 11:08, James Courtier-Dutton wrote:
> But, r should be
> 5.26300791462049950360708478127784... or
> -1.020177392559086973318201985281...
> according to wolfram alpha and most arbitrary maths libs I tried.
>
> I need to do a bit more digging, but this might point to a bug in the
> cpu instruction FPREM1
No, this is all as expected. The instructions are documented to use
a 66-bit approximation of Pi (really 64 bits, but the next two
happen to be 0).
Ada requires a relative error less than 2 eps for arguments in the
range - 2.0**32 .. 2.0**32, for a binary floating point type
with 64 bits of mantissa. So, he GCC Ada run time library uses
a 150-bit or so approximation to ensure accurate argument reduction
over the required range.
Even with an approximation of Pi that is not precise enough to
guarantee a small relative error of the result, there is still
value in consistent argument reduction. For example, a point
(Sin (X), Cos (X)) should always be close to the unit circle,
regardless of the magnitude of X.
-Geert