/* ** cordic -- program to calculate various functions ** (e.g. trigonometric) using CORDIC techniques ** ** original author unknown ** modified by Joseph B. Evans, 11/15/91 ** evans@shannon.tisl.ukans.edu */ #include #include "cordic.h" main(ac, av) int ac; char **av; { long x, y; long r, theta; long sine, cosine; int bits, msbits; if (ac == 2) { bits = 32; msbits = 10; theta = (long)atoi(av[1]); } else if (ac == 4) { bits = (long)atoi(av[1]); msbits = (long)atoi(av[2]); theta = (long)atoi(av[3]); } else { printf("usage: %s [bits msbits] theta\n",av[0]); exit(1); } theta *= (1<<(bits-msbits)); (void) cordic_init(bits,msbits); fxunitvec(&cosine,&sine,theta,bits); /* printf("theta = %.9f\n",theta/(double)(1<<(bits-msbits))); */ printf("cosine = %.9f\n",cosine/(double)(1<<(bits-1))); printf("sine = %.9f\n",sine/(double)(1<<(bits-1))); }