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
 Albert Chan Senior Member Posts: 2,516 Joined: Jul 2018
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)
 « Next Oldest | Next Newest »

 Messages In This Thread HP 17B Solver - another ARCTAN(Y/X) approximation - Martin Hepperle - 05-15-2021, 09:14 AM RE: HP 17B Solver - another ARCTAN(Y/X) approximation - Albert Chan - 05-15-2021, 11:01 PM RE: HP 17B Solver - another ARCTAN(Y/X) approximation - Martin Hepperle - 05-16-2021, 08:42 AM RE: HP 17B Solver - another ARCTAN(Y/X) approximation - Albert Chan - 05-16-2021, 01:03 PM RE: HP 17B Solver - another ARCTAN(Y/X) approximation - Albert Chan - 05-16-2021, 05:04 PM RE: HP 17B Solver - another ARCTAN(Y/X) approximation - Albert Chan - 05-17-2021, 12:43 PM RE: HP 17B Solver - another ARCTAN(Y/X) approximation - Albert Chan - 05-31-2021, 04:42 PM RE: HP 17B Solver - another ARCTAN(Y/X) approximation - Albert Chan - 05-31-2021, 07:30 PM RE: HP 17B Solver - another ARCTAN(Y/X) approximation - Albert Chan - 05-31-2021, 09:51 PM RE: HP 17B Solver - another ARCTAN(Y/X) approximation - Martin Hepperle - 06-01-2021, 03:16 PM RE: HP 17B Solver - another ARCTAN(Y/X) approximation - Albert Chan - 06-01-2021, 04:38 PM RE: HP 17B Solver - another ARCTAN(Y/X) approximation - Albert Chan - 08-29-2021, 11:39 PM RE: HP 17B Solver - another ARCTAN(Y/X) approximation - Albert Chan - 05-17-2021 06:01 PM RE: HP 17B Solver - another ARCTAN(Y/X) approximation - Albert Chan - 08-19-2021, 02:42 AM

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