Sin(x) and Cos(x) based on CORDIC

During the 50ies, Jack Volder invented the CORDIC algorithm. This clever algorithm can calculate hyperbolic and trigonometric functions, and do vector rotations. A highly desirable property of the algorithm is that it does not use any multiplications; it only needs add, subtract and right-shift operations and a small lookup-table.

While other, more cycle efficient, ways exist to calculate these functions on a general purpose CPU or a DSP, the CORDIC algorithm still has its place in small devices, such as 8-bit systems, or in very high speed systems, such as digital down-converters and numerically controlled oscillators.

As an experiment I implemented the CORDIC algorithm in C to calculate sin(x) and cos(x) using BCD arithmetic. I chose BCD arithmetic so I could get arbitrary precision, even on 8-bit processors.

Currently, the accuracy of the results is limited by the precision of the lookup-table but it already exceeds the capability of the built-in float-point processor of my PC.

The code is available on GitHub under the MIT license for your enjoyment!