Sine and Cosine Accuracy

Uros Bizjak uros@kss-loka.si
Thu May 26 23:31:00 GMT 2005


Hello!

>Fair enough, so with 64 bit floats you have no right to expect an
>accurate answer for sin(2^90).  However, you DO have a right to expect
>an answer in the range [-1,+1] rather than the 1.2e+27 that Richard
>quoted.  I see no words in the description of
>-funsafe-math-optimizations to lead me to expect such a result.
>
  The source operand to fsin, fcos and fsincos x87 insns must be within 
the range of +-2^63, otherwise a C2 flag is set in FP status word that 
marks insufficient operand reduction. Limited operand range is the 
reason, why fsin & friends are enabled only with 
-funsafe-math-optimizations.

  However, the argument to fsin can be reduced to an acceptable range by 
using fmod builtin. Internally, this builtin is implemented as a very 
tight loop that check for insufficient reduction, and could reduce 
whatever finite value one wishes.

  Out of curiosity, where could sin(2^90) be needed? It looks rather big 
angle to me.

Uros.



More information about the Gcc mailing list