Here is my Arc Tangent code:
Code:
#define ATAN_COUNT 64
char rom ATAN_ARRAY[64] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16,
17, 18, 19, 21, 22, 23, 25, 26, 27, 29, 30, 32, 34,
36, 37, 39, 41, 43, 46, 48, 50, 53, 56, 59, 62, 66,
69, 74, 78, 83, 88, 95, 101, 109, 118, 128, 140, 154,
171, 192, 218, 253, 299, 367, 473, 663, 1106, 3319};
char atan (char Num)
{
char Index = 0;
char Value = 0;
char IsDone = 0;
LOOP:
if (ATAN_ARRAY[Index] > Num)
Value--;
if (ATAN_ARRAY[Index] >= Num)
IsDone = 255;
else if (Index >= ATAN_COUNT - 1) //was ATAN_COUNT + 1
{
IsDone = 255;
Value = 64;
}
if (IsDone)
goto LOOP_DONE;
else
{ Value++; Index++; }
goto LOOP;
LOOP_DONE:
return Value;
}
The lookup table is compressed. If I were to use a regular variety than it would be 3320 elements long! Instead, I put the location of the element that the value changes. That's why I loop. I think this will work, but I'm not sure.
[edit]that chould be ATAN_COUNT - 1 not ATAN_COUNT + 1 at line 19[/edit]