Cosine Functions on 4K ROM

Author(s): Lori Olson
Publication: Syntax
Pub Details: Syntax/Syntax ZX80 v2 n9 (Volume 2, Issue 9)
Date: September 1981
Pages: 16

Here’s a way to approximate cosines with your 4K ROM (see p.2 for sine functions).

This equation simulates a cosine curve:

1000cos(X)=[10000+32X-121X²+34X³]/10

Program cosine using:

B=-(((X*121)/15)*X)/5+((X**2/3)*X/45)*34/75
C=(10000+32*X/45+B)/10

where C is 1000 times cos(X).

For angles greater than 45°, use the relation cos(X)=sin(90-X). These equations and the ones on p.2 give sines and cosines within 3 in the least significant digit.


Extend the method of calculating sine and cosine on 4K (pp.2&16) to other slowly varying functions. Use cubic approximations. Example: for sine, 4 X-values equally spaced on the curve create 4 equations:

10000sin(0)=a+b(0)+c(0)²+d(0)³
10000sin(15)=a+b(15)+c(15)²+d(15)³
10000sin(30)=a+b(30)+c(30)²+d(30)³
10000sin(45)=a+b(45)+c(45)²+d(45)³

Solve these to get a general equation: 10000sin(X)=a+bX+cX²+dX³

Divide both sides by 10 for greater accuracy. To avoid overflows, multiply and divide carefully when programming the resulting equation.