Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Some externally defined stuff
- //#define SCALE (sizeof(BASE) * 8)
- //#define RADIX 16
- //#define BASIS ((BASE)1 << RADIX)
- //#define PI (BASE)(3.1415926536897932384626 * BASIS)
- //typedef Sclr int64_t;
- //typedef Angl int64_t;
- Sclr
- engineer_math_sin(Angl input)
- {
- // A sine approximation via a fifth-order polynomial.
- int64_t c, x, x2, o;
- static const int64_t
- A = PI/2, // PI/2
- B = PI - (5 * BASIS)/2, // PI - 5/2
- C = (PI - 3 * BASIS)/2, // (PI - 3)/2
- S = (BASIS << (RADIX + 1)) / PI; // 2/PI
- x = MULT(input, S);
- x = x << (62 - RADIX); // Shift to full s64 range (Q16->Q62)
- if( (x ^ (x << 1)) < 0) // Test for quadrant 1 or 2
- x = ((int64_t)1 << 63) - x;
- x = x >> (62 - RADIX);
- x2 = MULT(x, x); // Ax - Bx^3 + Cx^5
- o = B - MULT(C, x2); // Ax - x(Bx^2 - Cx^4)
- o = A - MULT(o, x2); // x(A - (Bx^2 - Cx^4)
- o = MULT(o, x); // x(A - x^2(B - Cx^2))
- return o;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement