Post Reply 
HP 17B Solver - another ARCTAN(Y/X) approximation
05-15-2021, 11:01 PM (This post was last modified: 05-16-2021 01:34 AM by Albert Chan.)
Post: #2
RE: HP 17B Solver - another ARCTAN(Y/X) approximation
(05-15-2021 09:14 AM)Martin Hepperle Wrote:  I guess there are options to reduce the complexity of the quadrant handling.

Code:
function my_atan2(y, x)
    local z, offset, p = y/x, 0, (y >= 0 and pi or -pi)
    if abs(z)>1 then z, offset = -x/y, p/2 end
    if x < 0 then offset = p - offset end -- Q2, Q3
    local s = z*z
    z = z * (((15159/35*s + 4213)*s + 9867)*s + 6435) /
      ((((35*s + 1260)*s + 6930)*s + 12012)*s + 6435)
    return z + offset
end

This may be simpler in logic, letting atan() part take care of Q1 and Q4.
Also, returned angles matched most implementation of atan2, -pi < angle ≤ pi

Reference: https://mae.ufl.edu/~uhk/ARCTAN-APPROX-PAPER.pdf

---

What is the reason for 0 = (R-R) + ... ?

Comment: I had matched the top/bottom polynomial constant term.
(so that it is more obvious to see formula gives atan(ε) ≈ ε, as expected)

Coefficient 15159/35 is not an integer, we might as well adjust it to reduce relative error.
Replace 15159/35 by 433.1338, we reduced max. rel error from 1.2e-6, down to 2.9e-7
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: HP 17B Solver - another ARCTAN(Y/X) approximation - Albert Chan - 05-15-2021 11:01 PM



User(s) browsing this thread: 1 Guest(s)