aki@speech1.cs.cmu.edu (Yoshiaki Ohshima) (08/30/89)
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
news@ism780c.isc.com (News system) (08/31/89)
In article <6002@pt.cs.cmu.edu> aki@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.
gwyn@smoke.BRL.MIL (Doug Gwyn) (08/31/89)
In article <6002@pt.cs.cmu.edu> aki@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? The library versions should be close to optimum. The ones I know of are pretty fast. >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? This is simply a numerical analysis question. If you're not near 0, then the atan curve is rather flat and a bisection search will not work well. Why are you searching?
mcdonald@uxe.cso.uiuc.edu (08/31/89)
>Hello, does anyone know if there are any 'arc tangent' routines, which run >faster than atan() and atan2() of the standard C math library? Range reduce the problem down to 0 to pi/4 (from pi/4 to pi/2 there is an obvious geometrical relation to 0 to pi/4). Then use a table lookup with both starting points and slopes stored at a suitable number of points. For high accuracy you might need to store quadratic coefficients also. Doug McDonald