Post Reply 
HP-35 style trig functions
01-15-2019, 07:10 AM
Post: #10
RE: HP-35 style trig functions
(01-15-2019 03:43 AM)Dan Wrote:  "The preceding approach could be reworked using powers of 1/10 instead of powers of 1/2; it is only necessary (as was done for the hyperbolic examples) to work with lists that contain many duplicate entries".

You only have to add an additional loop in the cordic function and adjust K:
Code:
from math import sqrt, sin, cos, atan

N = 16
ATAN  = [atan(10**(-i)) for i in range(N)]

P, d = 1.0, 1.0
for i in range(N):
    P *= (1 + d*d)
    d /= 10

K = sqrt(P)**9

def cordic(x, y, z, d, A):
    for a in A:
        for _ in range(9):
            s = cmp(z, 0)
            z -= s * a
            x, y = x - y * s * d, y + x * s * d
        d /= 10
    return x, y, z

This results in:

arg = 0.4
cordic(1/K, 0, arg, 1.0, ATAN)
(0.9210609940028851, 0.38941834230865136, -2.986136694229353e-16)

Compare this to:

>>> cos(arg), sin(arg)
(0.9210609940028851, 0.3894183423086505)


The cost is a possible unnecessary flipping between two states. But you can avoid the calculation of the square root.

Cheers
Thomas
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
HP-35 style trig functions - Druzyek - 01-13-2019, 08:32 PM
RE: HP-35 style trig functions - pier4r - 01-13-2019, 08:37 PM
RE: HP-35 style trig functions - Druzyek - 01-14-2019, 12:56 AM
RE: HP-35 style trig functions - Dan - 01-14-2019, 01:31 AM
RE: HP-35 style trig functions - Druzyek - 01-14-2019, 02:34 AM
RE: HP-35 style trig functions - Dan - 01-15-2019, 03:43 AM
RE: HP-35 style trig functions - Thomas Klemm - 01-15-2019 07:10 AM
RE: HP-35 style trig functions - Druzyek - 01-15-2019, 11:49 PM
RE: HP-35 style trig functions - Druzyek - 08-28-2023, 12:19 AM



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