Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static long[] isincos(long phasein) {
- long sinout, cosout;
- long OUTBITS = 16;
- long BITSPERCYCLE = 16;
- long BITSPERQUARTER = (BITSPERCYCLE - 2);
- long BITS = 8;
- long ONE = 1 << BITS;
- long HALF = ONE / 2;
- long C = 70710 * ONE / 100000;
- // Modulo phase into quarter, convert to float 0..1
- long modphase = (phasein & (1 << BITSPERQUARTER) - 1) * ONE / (1 << BITSPERQUARTER);
- // Extract quarter bits
- long quarter = phasein & (3 << BITSPERQUARTER);
- // Recognize quarter
- if (quarter == 0) {
- // First quarter, angle = 0 .. pi/2
- long x = modphase - HALF; // 1 sub
- long temp = ((2 * ONE - 4 * C) * x / ONE) * x / ONE + C; // 2 mul, 1 add
- sinout = temp + x; // 1 add
- cosout = temp - x; // 1 sub
- } else if (quarter == 1 << BITSPERQUARTER) {
- // Second quarter, angle = pi/2 .. pi
- long x = HALF - modphase; // 1 sub
- long temp = ((2 * ONE - 4 * C) * x / ONE) * x / ONE + C; // 2 mul, 1 add
- sinout = x + temp; // 1 add
- cosout = x - temp; // 1 sub
- } else if (quarter == 2 << BITSPERQUARTER) {
- // Third quarter, angle = pi .. 1.5pi
- long x = modphase - HALF; // 1 sub
- long temp = ((4 * C - 2 * ONE) * x / ONE) * x / ONE - C; // 2 mul, 1 sub
- sinout = temp - x; // 1 sub
- cosout = temp + x; // 1 add
- } else {
- // Fourth quarter, angle = 1.5pi..2pi
- long x = modphase - HALF; // 1 sub
- long temp = ((2 * ONE - 4 * C) * x / ONE) * x / ONE + C; // 2 mul, 1 add
- sinout = x - temp; // 1 sub
- cosout = x + temp; // 1 add
- }
- long arr[] = new long[2];
- arr[0] = sinout << (OUTBITS - BITS);
- arr[1] = cosout << (OUTBITS - BITS);
- return arr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement