#include #include #include "compatib.h" #define MAXSINES 359 // iSineVals array contains the sine values in the range [0 ... MAXSINES] // degrees (in 1 degree steps). These values are not the original sine values, // but the values got as the real values are multiplied by // 2^(bits in int - 2) INT iSineVals[360] = { 0, 285, 571, 857, 1142, 1427, 1712, 1996, 2280, 2563, 2845, 3126, 3406, 3685, 3963, 4240, 4516, 4790, 5062, 5334, 5603, 5871, 6137, 6401, 6663, 6924, 7182, 7438, 7691, 7943, 8192, 8438, 8682, 8923, 9161, 9397, 9630, 9860, 10086, 10310, 10531, 10748, 10963, 11173, 11381, 11585, 11785, 11982, 12175, 12365, 12550, 12732, 12910, 13084, 13254, 13420, 13582, 13740, 13894, 14043, 14188, 14329, 14466, 14598, 14725, 14848, 14967, 15081, 15190, 15295, 15395, 15491, 15582, 15668, 15749, 15825, 15897, 15964, 16025, 16082, 16135, 16182, 16224, 16261, 16294, 16321, 16344, 16361, 16374, 16381, 16384, 16381, 16374, 16361, 16344, 16321, 16294, 16261, 16224, 16182, 16135, 16082, 16025, 15964, 15897, 15825, 15749, 15668, 15582, 15491, 15395, 15295, 15190, 15081, 14967, 14848, 14725, 14598, 14466, 14329, 14188, 14043, 13894, 13740, 13582, 13420, 13254, 13084, 12910, 12732, 12550, 12365, 12175, 11982, 11785, 11585, 11381, 11173, 10963, 10748, 10531, 10310, 10086, 9860, 9630, 9397, 9161, 8923, 8682, 8438, 8191, 7943, 7691, 7438, 7182, 6924, 6663, 6401, 6137, 5871, 5603, 5334, 5062, 4790, 4516, 4240, 3963, 3685, 3406, 3126, 2845, 2563, 2280, 1996, 1712, 1427, 1142, 857, 571, 285, 0, -285, -571, -857, -1142, -1427, -1712, -1996, -2280, -2563, -2845, -3126, -3406, -3685, -3963, -4240, -4516, -4790, -5062, -5334, -5603, -5871, -6137, -6401, -6663, -6924, -7182, -7438, -7691, -7943, -8192, -8438, -8682, -8923, -9161, -9397, -9630, -9860, -10086, -10310, -10531, -10748, -10963, -11173, -11381, -11585, -11785, -11982, -12175, -12365, -12550, -12732, -12910, -13084, -13254, -13420, -13582, -13740, -13894, -14043, -14188, -14329, -14466, -14598, -14725, -14848, -14967, -15081, -15190, -15295, -15395, -15491, -15582, -15668, -15749, -15825, -15897, -15964, -16025, -16082, -16135, -16182, -16224, -16261, -16294, -16321, -16344, -16361, -16374, -16381, -16384, -16381, -16374, -16361, -16344, -16321, -16294, -16261, -16224, -16182, -16135, -16082, -16025, -15964, -15897, -15825, -15749, -15668, -15582, -15491, -15395, -15295, -15190, -15081, -14967, -14848, -14725, -14598, -14466, -14329, -14188, -14043, -13894, -13740, -13582, -13420, -13254, -13084, -12910, -12732, -12550, -12365, -12175, -11982, -11785, -11585, -11381, -11173, -10963, -10748, -10531, -10310, -10086, -9860, -9630, -9397, -9161, -8923, -8682, -8438, -8191, -7943, -7691, -7438, -7182, -6924, -6663, -6401, -6137, -5871, -5603, -5334, -5062, -4790, -4516, -4240, -3963, -3685, -3406, -3126, -2845, -2563, -2280, -1996, -1712, -1427, -1142, -857, -571, -285 }; //////////////////////////////////////////////////////////////////////////// /* SIN() returns sine of its argument scaled (multiplied) by SCALE constant. Parameter Description iDeg Angle in degrees (can be negative and > 360) Returns The scaled sine value as an integer */ //////////////////////////////////////////////////////////////////////////// INT SIN(INT iDeg) { if (abs(iDeg) > MAXSINES) iDeg %= (MAXSINES+1); if (iDeg >= 0) return iSineVals[iDeg]; else return -iSineVals[abs(iDeg)]; } //////////////////////////////////////////////////////////////////////////// /* COS() returns cosine of its argument scaled (multiplied) by SCALE constant. Parameter Description iDeg Angle in degrees (can be negative and > 360) Returns The scaled cosine value as an integer */ //////////////////////////////////////////////////////////////////////////// INT COS(INT iDeg) { return SIN(90 - x); } main() { printf("\n%d\n", SIN(-450)); }