/* * i8atan2.c * begin 20190611 true * * copied and fixed up from teh internets */ #include static int8_t iat2(int8_t y, int8_t x) { return ((y * 32 + (x / 2)) / x) * 2; } int8_t i8atan2(int8_t y, int8_t x) { // determine octant if (y >= 0) { // oct 0,1,2,3 if (x >= 0) { // oct 0,1 if (x > y) { return iat2(-y, -x) / 2 + (0 * 32); } else { if (y == 0) return 0; // (x=0,y=0) return -iat2(-x, -y) / 2 + (2 * 32); } } else { // oct 2,3 if (x >= -y) { return iat2(x, -y) / 2 + (2 * 32); } else { return -iat2(-y, x) / 2 + (4 * 32); } } } else { // oct 4,5,6,7 if (x < 0) { // oct 4,5 if (x < y) { return iat2(y, x) / 2 + (-4 * 32); } else { return -iat2(x, y) / 2 + (-2 * 32); } } else { // oct 6,7 if (-x >= y) { return iat2(-x, y) / 2 + (-2 * 32); } else { return -iat2(y, -x) / 2 + (-0 * 32); } } } }