fast arc tangent routine available?

News system news at ism780c.isc.com
Thu Aug 31 07:31:56 AEST 1989


In article <6002 at pt.cs.cmu.edu> aki at speech1.cs.cmu.edu (Yoshiaki Ohshima) writes:
>Hello, does anyone know if there are any 'arc tangent' routines, which run
>faster than atan() and atan2() of the standard C math library?
>
>I am now using Micro-Vax-II and (occasionally) PMAX, and have an impression
>that my simple-minded table lookup using bisection search doesn't seem to
>work well. Has anyone ever worked on this?
>
>						--aki

Since the table has to span an infinite range, table lookup does not seem to
be very effective.  Assuming you need only three or so decimal digits of
accuracy, here is a formula from Cecil Hastings, Approximations for Digital
Computers.  It works for all x between 0 and infinity.  If x is negative,
change the sign of x and the sign of the answer.  The maximum error in atan
is plus or minus .0005.

    let y = (x-1)/(x+1)
    let z = y*y

then
     atan(x) = .785398 + (.995354 + (-.288679 + .079331*z)*z)*y

This is a fairly quick method.  If you need to compute atan from inside a
loop, than write the above code inline to avoid subroutine call overhead.

     Hope this helps,
	Marv Rubinstein

PS: I leave it as an exercise for the reader to use this formula as the basis
for an atan2 routine.

PPS: The first term is pi/4 if you had not guessed.



More information about the Comp.unix.questions mailing list