I must do some calculations that need to use trigonometric functions, and especially the atan
one. The code will run on an Atmega328p, and for efficiency sake, I can't use float
s: I'm using fixed point numbers. Thus, I can't use the standard atan
function.
I which to have a function which take a value in fixed point format s16_10 (signed, 16 bits width, point in 10th position), and returns a s16_6 format. The input will be between 0 and 1 (so 0 and 210), so the output, in degrees, will be between -45 and 45 (so -45 * 26 and 45 * 26).
Let's say that Y is the fixed point, s16_6 representation of y, the real angle of the arc, and x such as atan(x) = y
, and X the s16_10 representation of x. I start with approximating the atan
function, from (0,1) to (-45,45) with a 4th degrees polynomial, and found that we can use:
y ~= 8.11 * x^4 - 19.67 * x^3 - 0.93 * x^2 + 57.52 * x + 0.0096
Which leads to:
Y ~= (8.11 * X^4)/2^34 - (19.62* X^3)/2^24 - (0.93 * X^2)/2^14 + (57.52*X)/2^4 + 0.0069 * 2^6
And here am I stuck... On the one hand, computing the X^4
will lead to a 0 for one fifth of the definition interval, and on the other and the 2n4n in {3, 2, 1} will often lead also to a zero value... How could I do ?