Changeset 1006


Ignore:
Timestamp:
Oct 4, 2011, 3:35:55 PM (11 years ago)
Author:
sam
Message:

core: replace the cos(real) implementation with a simple call to
sin(pi/2-x). No loss in precision in theory.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/real.cpp

    r1004 r1006  
    739739real cos(real const &x)
    740740{
    741     bool switch_sign = false;
    742     real absx = fmod(fabs(x), real::R_PI << 1);
    743 
    744     if (absx > real::R_PI)
    745         absx = (real::R_PI << 1) - absx;
    746 
    747     if (absx > real::R_PI_2)
    748     {
    749         absx = real::R_PI - absx;
    750         switch_sign = true;
    751     }
    752 
    753     real ret = 0.0, fact = 1.0, xn = 1.0, x2 = absx * absx;
    754     for (int i = 1; ; i += 2)
    755     {
    756         real newret = ret + xn / fact;
    757         if (ret == newret)
    758             break;
    759         ret = newret;
    760         xn *= x2;
    761         fact *= (real)(-i * (i + 1));
    762     }
    763 
    764     /* Propagate sign */
    765     if (switch_sign)
    766         ret.m_signexp ^= 0x80000000u;
    767     return ret;
     741    return sin(real::R_PI_2 - x);
    768742}
    769743
Note: See TracChangeset for help on using the changeset viewer.