Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const double MY_PI = 3.141592653589793238463;
- typedef int64_t Angle;
- typedef int64_t Scalar;
- Scalar sine5_a(Angle input)
- {
- static const Scalar qB = sizeof(Scalar)*8, qN = 17-2, qA = 16, qP = 24, M = (1<<24);
- static const Scalar
- A = 1*MY_PI * M, // Q24
- B = (2*MY_PI - 5) * M, // Q24
- C = (1*MY_PI - 3) * M; // Q24
- Scalar x, x2, y;
- x = input << ((qB-2)-qN);
- if ( (x^(x<<1)) < 0 )
- x = (1ll<<(qB-1)) - x;
- x = x >> ((qB-2)-qN); // Q15
- x2 = x*x; // Q30
- y = C*x2 >> 30; // Q24
- y = B - y; // Q24
- y = y*x2 >> 24; // Q30
- y = (A<<(30-qP)) - y; // Q30
- y = y*x; // Q45
- y = y >> (45-16 + 1); // Q16
- return y;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement