SHARE
TWEET

Untitled

a guest Apr 26th, 2017 114 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const double MY_PI = 3.141592653589793238463;
  2. typedef int64_t Angle;
  3. typedef int64_t Scalar;
  4.  
  5. Scalar sine5_a(Angle input)
  6. {
  7.     static const Scalar qB = sizeof(Scalar)*8, qN = 17-2, qA = 16, qP = 24, M = (1<<24);
  8.     static const Scalar
  9.         A =  1*MY_PI      * M,      // Q24
  10.         B = (2*MY_PI - 5) * M,      // Q24
  11.         C = (1*MY_PI - 3) * M;      // Q24
  12.  
  13.     Scalar x, x2, y;
  14.  
  15.     x = input << ((qB-2)-qN);      
  16.     if ( (x^(x<<1)) < 0 )
  17.         x = (1ll<<(qB-1)) - x;
  18.     x  = x >> ((qB-2)-qN);      // Q15
  19.  
  20.     x2 = x*x;                   // Q30
  21.     y  = C*x2 >> 30;            // Q24
  22.     y  = B - y;                 // Q24
  23.     y  = y*x2 >> 24;            // Q30
  24.     y =  (A<<(30-qP)) - y;      // Q30
  25.     y =  y*x;                   // Q45
  26.     y =  y >> (45-16 + 1);      // Q16
  27.  
  28.     return y;
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top