I've started looking for easy, portable, fast and imprecise 8-bit trigonometric functions to use in the game I'm writing in C.
I've attached a 320 element binary table, with of course the obligatory initial two null bytes. Use it like this:
foo = TRIG_TABLE[ x ]; // sin(x). x is from 0 to 255, representing 0 to 360 degrees.
bar = TRIG_TABLE[ x + 64 ]; // cos(x).
foo_sign = foo & 128;
foo_val = foo & 127;
bar_sign = bar & 128;
bar_val = bar & 127;
The indexed byte value has two parts: the 8th bit is the sign bit. The remaining 7 bits represent the value, in hundredths.
Yazwho and Desertfish noted that sin and cos overlap, so only one table is needed, as long as you start COS indexing at an offset of 64 (= 90 degrees). In other words, cos(x) = sin(x+64). Since space isn't THAT critical, the table is 320 bytes long.
* * *
I found this interesting idea over here: https://geometricolor.wordpress.com/2017/01/06/fast-approximations-of-the-sine-and-cosine-functions/
Quote
The length of the table should be a power of 2 plus one for linear approximation. Then we can use bitwise-and (&) to impose periodicity instead of the much slower modulus (%) operation.
TRIG