# Arctan approximation example

Started by July 30, 2003
```>> 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&#2013265929;

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 <bg4dkq\$dll\$1@nntp.itservices.ubc.ca>:

> 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).
```
```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
```