This is the mail archive of the gcc@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: Sine and Cosine Accuracy


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.


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