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
Hi,
On Fri, 3 Feb 2012, Richard Guenther wrote:
> > int main(void)
> > {
> > Âdouble a = 4.47460300787e+182;
> > slipped = -1.141385
> > That is correct.
> >
> > slipped = -0.432436
> > That is obviously incorrect.
How did you determine that one is correct and the other obviously
incorrect? Note how the input number is much too large for the usual
implementations of the trigonometric functions to return any sensible
result. Even arbitrary precision calculators return different numbers (I
tried some).
> > Here we have one sincos call, and it works wrong.
> >
> > Why gcc performs such buggy optimization, and may I switch it off
> > somehow? Or may be I don't understand something and problem is in my
> > code?
>
> Your math library is broken then (you can verify this yourself by
> using sincos). You can use -fno-builtin-sincos to disable this
> optimization.
No normal math library supports such an extreme range, even basic
identities (like cos^2+sin^2=1) aren't retained with such inputs.
Ciao,
Michael.