Post Reply 
HP 17B Solver - another ARCTAN(Y/X) approximation
05-17-2021, 06:01 PM (This post was last modified: 05-18-2021 11:15 AM by Albert Chan.)
Post: #7
RE: HP 17B Solver - another ARCTAN(Y/X) approximation
This version split atan(z) = 3*atan(h) + atan(ε)

At the cost of +-*/ (sum-of-tangents formula), we reduced max rel. error to 5.7e-15

atan(1) = 3*atan(39897/148903) + atan(35024948800/1295182203518473)
            = 3*atan(0.26793953...) + atan(0.00002704...)

Again, we have h ≈ tan(pi/12) = 2 - √3 = 0.26794919... , as expected

Note that atan(ε) ≈ ε has errors with opposite sign, cancelled errors of first term estimate.
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
    x = z * ((14031*s + 73386)*s + 72171) /
            (((4096*s + 90693)*s + 284310)*s + 216513)
    y = (z-x)/(1+z*x)   -- atan(z) = 3*atan(x) + atan(y)
    y = (y-x)/(1+y*x)
    y = (y-x)/(1+y*x)   -- atan(y) approximated by y
    s = x*x             -- atan(x) approximated by below
    x = x * (((15159/35*s + 4213)*s + 9867)*s + 6435) /
      ((((35*s + 1260)*s + 6930)*s + 12012)*s + 6435)
    return 3*x + y + offset
end

Comment: replace coef 15159/35 by 433.1142858 will reduce max. rel. error to 2.0e-15
Note that adjustment is minor, 15159/35 = 433.1(142857)
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-17-2021 06:01 PM



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