>> On 30 Jul 2003 05:02:11 -0700, jomfrusti@image.dk >> (=?ISO-8859-1?Q?Ren=E9?=) wrote: >> >> >Is it possible to get a fast fix point Arctan routine written >> >in C using the principle with a lookup table or perhaps >> >another principle? >> > >> >Regards, >> >Ren�An interesting way to compute arctan has appeared two days ago on sci.math. But the OP wasn't after speed, and the formula has a whole bunch of divisions. It is intended for single precision. Martin Robert Israel wrote in message: > It suffices to be able to compute arctan(x) for x in [0,1]. > Try > .0318159928972*y+.950551425796+3.86835495723/(y+8.05475522951+ > 39.4241153441/(y-2.08140771798-.277672591210/(y-8.27402153865+ > 95.3157060344/(y+10.5910515515)))) > > where y = 2*x-1. The maximum error is about 8*10^(-10).

# Arctan approximation example

Started by ●July 30, 2003

Posted by ●July 31, 2003

Posted by ●August 9, 2003

Martin Eisenberg wrote: ...> An interesting way to compute arctan has appeared two days ago on > sci.math. But the OP wasn't after speed, and the formula has a whole > bunch of divisions. It is intended for single precision....> Robert Israel wrote: > > > It suffices to be able to compute arctan(x) for x in [0,1]. > > Try > > .0318159928972*y+.950551425796+3.86835495723/(y+8.05475522951+ > > 39.4241153441/(y-2.08140771798-.277672591210/(y-8.27402153865+ > > 95.3157060344/(y+10.5910515515)))) > > > > where y = 2*x-1. The maximum error is about 8*10^(-10).That's a minmax rational polynomial approximation for arccos(1/Sqrt(1+x^2)) = arctan(x) for x >= 0 with degree 5 in the numerator and degree 4 in the denominator (just multiply the continued fraction representation out). This uses only one division. The accuracy is a bit high for 32-bit floating-point, a minmax rational polynomial function with degree 4 / degree 2 is enough for that: 0.05030176425872175099 (-6.9888366207752135 + x)(3.14559995508649281e-7 + x)(2.84446368839622429 + 0.826399783297673451 x + x^2) / (1 + 0.1471039133652469065841349249 x + 0.644464067689154755092299698 x^2) The max absolute error in [0,1] is about 3.2e-7 which is still slightly better than 32bit floating-point representation of arctan(x) in [0,1]. Regards, Andor

Posted by ●July 30, 2003

Rene, What is "fast" often depends on the low level instruction set of the DSP/computer. You could take a look at the Cordic algorithm for an atan2() or atan(). The underlying idea is that you are going to rotate an (x,y) vector to align with the positive x-axis through a series of known shifts that are computationally efficient to apply. The final result will be the negative of the sum of shifts applied to get as close to the x-axis as you wanted. Generally, each additional phase bit output costs a sign check, 2 shifts and 2 accumulates (conditionally add or subtract), plus any addressing overhead. There is a known scaling required (multiply) that can be at the end, beginning, or could be distributed. There is a discussion of it in an appendix in Frerking. Besides a typo, he needs to extend his index range to one lower to be able to compute atan2 on any angle in the [0,90] degree range he claims. You need to rotate the vector into the [0,90] degree range using x,y exchanges and sign adjustments, accumulating the corresponding phase rotations in the process, before you launch into his algorithm. Dirk Dirk A. Bell DSP Consultant "Ren�"wrote in message news:c9a8aff3.0307300402.5dab2c11@posting.google.com... > Is it possible to get a fast fix point Arctan routine written in C > using the principle with a lookup table or perhaps another principle? > > Regards, > Ren�

Posted by ●July 30, 2003