#include long rinvtan(long x, long y); extern short Tinvtan[]; // returns inverse tangent from x and y values // return value is of form 4096 = 360 degrees // where x = y = 0 and the result is undefined the function returns 0 long rinvtan(long x, long y) { long t; if (x == 0 && y == 0) return 0; if (fabs(x) > fabs(y)) { t = (y << 8) / x; if (t >= 0) return Tinvtan[t & 255] + (x < 0 ? 2048 : 0); return (x < 0 ? 2048 : 4096) - Tinvtan[(-t) & 255]; } t = (x << 8) / y; if (t >= 0) return (y < 0 ? 3072 : 1024) - Tinvtan[t & 255]; return Tinvtan[(-t) & 255] + (y < 0 ? 3072 : 1024); } // table for inverse tangent (of form 512 = 90 degrees) short Tinvtan[] = { 0, 3, 5, 8, 10, 13, 15, 18, 20, 23, 25, 28, 31, 33, 36, 38, 41, 43, 46, 48, 51, 53, 56, 58, 61, 63, 66, 69, 71, 74, 76, 79, 81, 84, 86, 89, 91, 94, 96, 99, 101, 104, 106, 108, 111, 113, 116, 118, 121, 123, 126, 128, 131, 133, 136, 138, 140, 143, 145, 148, 150, 152, 155, 157, 160, 162, 164, 167, 169, 172, 174, 176, 179, 181, 183, 186, 188, 190, 193, 195, 197, 200, 202, 204, 207, 209, 211, 214, 216, 218, 220, 223, 225, 227, 229, 232, 234, 236, 238, 241, 243, 245, 247, 249, 252, 254, 256, 258, 260, 262, 265, 267, 269, 271, 273, 275, 277, 279, 282, 284, 286, 288, 290, 292, 294, 296, 298, 300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 322, 324, 326, 328, 330, 332, 334, 336, 338, 340, 342, 344, 346, 347, 349, 351, 353, 355, 357, 359, 360, 362, 364, 366, 368, 370, 371, 373, 375, 377, 379, 380, 382, 384, 386, 387, 389, 391, 393, 394, 396, 398, 399, 401, 403, 405, 406, 408, 410, 411, 413, 415, 416, 418, 419, 421, 423, 424, 426, 428, 429, 431, 432, 434, 435, 437, 439, 440, 442, 443, 445, 446, 448, 449, 451, 452, 454, 455, 457, 458, 460, 461, 463, 464, 466, 467, 469, 470, 471, 473, 474, 476, 477, 479, 480, 481, 483, 484, 486, 487, 488, 490, 491, 492, 494, 495, 496, 498, 499, 500, 502, 503, 504, 506, 507, 508, 509, 511 };