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)
)
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement