/* Sine Table */// each of these 129 values is 16384 * sin(x[pibits]), where x is the offset in the table.unsigned short sinVals[129] = { 0, 201, 402, 603, 804, 1005, 1205, 1406, 1606, 1806, 2006, 2205, 2404, 2603, 2801, 2999, 3196, 3393, 3590, 3786, 3981, 4176, 4370, 4563, 4756, 4948, 5139, 5330, 5520, 5709, 5897, 6084, 6270, 6455, 6640, 6823, 7005, 7186, 7366, 7546, 7723, 7900, 8076, 8250, 8423, 8595, 8765, 8935, 9103, 9269, 9434, 9598, 9760, 9921, 10080, 10238, 10394, 10549, 10702, 10853, 11003, 11151, 11297, 11442, 11585, 11727, 11866, 12004, 12140, 12274, 12406, 12537, 12665, 12792, 12916, 13039, 13160, 13279, 13395, 13510, 13623, 13733, 13842, 13949, 14053, 14155, 14256, 14354, 14449, 14543, 14635, 14724, 14811, 14896, 14978, 15059, 15137, 15213, 15286, 15357, 15426, 15493, 15557, 15619, 15679, 15736, 15791, 15843, 15893, 15941, 15986, 16029, 16069, 16107, 16143, 16176, 16207, 16235, 16261, 16284, 16305, 16324, 16340, 16353, 16364, 16373, 16379, 16383, 16384};#define CosCalc(pibits,radius) (SinCalc((pibits+128),(radius)))long SinCalc(short pibits,short radius){ /* Declare variables and solve for quadrant and reference angle by using bit operations. */ unsigned short quadrant=(unsigned short)pibits >> 7; unsigned short reference_angle=(unsigned short)pibits & 127; short value; long result; /* Obtain sin(pibits)*16384 and store it into 'value' */ if (quadrant&1) //if angle is in Quadrant II or IV, invert the reference angle reference_angle=128-reference_angle; value=(short)sinVals[reference_angle]; if (quadrant&2) //if angle is in Quadrant III or IV, negate the value obtained from the table value=-value; /* Convert 'value' into sin(pibits)*radius and store it into 'result' */ result=(long)value*(long)radius; result>>=14; //2 to the 14th is 16384, so this divides out the 16384 from the sine value. return result;}