While working on my floating point routines, I decided to try my hand at writing an arctangent function. Some months ago (almost a year ago), I came up with a pretty efficient formula that was accurate enough for me (error <1/1024). Though this is not a suitable solution for a floating point library, I thought it might be useful in other applications (with games and whatnot). Especially on a device with a barrel shifter and hardware multiplication (like an ARM), this is pretty efficient:
(9x+2x3)/(9+5x2)
Conveniently, the constant multiplications are powers of 2 plus 1 or a power of 2, which can be done on an ARM in 1 instruction. On the z80, it would take only a few quick instructions. Aside from that, it requires 2 non-constant multiplications and a divide (plus two adds). For thirteen bits of accuracy on [-1,1]:
(240x+115x3)/(240+195x2+17x4)
I have been searching the internet for efficient ways to compute arctangent, and so I have read a bunch of papers and I have familiarised myself with a a handful of good techniques. However, I have yet to find documentation of the functions I have :[
I decided to post here and on Omnimaga so that others could easily have access to these functions. In the meantime, I documented my process/procedure, as well as a small overview of some other techniques (such as the AGM and CORDIC algorithms.) For the documentation, I have it here, but it isn't polished yet.
(as a word of advice, to extend these to all real number, there is an easy identity that can be applied when x>1 and it maintains the same accuracy:
pi/2-atan(1/x)=atan(x)
)
(9x+2x3)/(9+5x2)
Conveniently, the constant multiplications are powers of 2 plus 1 or a power of 2, which can be done on an ARM in 1 instruction. On the z80, it would take only a few quick instructions. Aside from that, it requires 2 non-constant multiplications and a divide (plus two adds). For thirteen bits of accuracy on [-1,1]:
(240x+115x3)/(240+195x2+17x4)
I have been searching the internet for efficient ways to compute arctangent, and so I have read a bunch of papers and I have familiarised myself with a a handful of good techniques. However, I have yet to find documentation of the functions I have :[
I decided to post here and on Omnimaga so that others could easily have access to these functions. In the meantime, I documented my process/procedure, as well as a small overview of some other techniques (such as the AGM and CORDIC algorithms.) For the documentation, I have it here, but it isn't polished yet.
(as a word of advice, to extend these to all real number, there is an easy identity that can be applied when x>1 and it maintains the same accuracy:
pi/2-atan(1/x)=atan(x)
)