#include <math.h>
#include <stdio.h>
#include "myfunc.h"

// a million steps, to get a large number of calculations
#define STEPS 1000000

int main() {
// sample program to verify the speed and precision of taylor series expansion of sine and cosine
// first, as a baseline, calculate the speed with the optimized standard library functions
	int i,j;
	double a,b;
	double av[4] = {0,0,0,0}; // 4 times the average of sine**2 + cosine**2 -1;
	double rms[4] = {0,0,0,0}; // and the RMS of them
	int tot=0;
	for (j=0; j<10; j++) for (i=0; i<STEPS; i++) {
		tot++;
                a = cos(i*10.0/STEPS);
		b = sin(i*10.0/STEPS);
		a = 1 - a*a -b*b; 
		av[0] +=a;
		rms[0] += a*a;
		a = mycos1((double) i*10.0/STEPS);
		b = mysin1((double) i*10.0/STEPS);
		a = 1 - a*a -b*b; 
		av[1] +=a;
		rms[1] += a*a;
		a = mycos2((float) i*10.0/STEPS);
		b = mysin2((float) i*10.0/STEPS);
		a = 1 - a*a -b*b; 
		av[2] +=a;
		rms[2] += a*a;
		a = mycos3((double) i*10.0/STEPS);
		b = mysin3((double) i*10.0/STEPS);
		a = 1 - a*a -b*b; 
		av[3] +=a;
		rms[3] += a*a;
	}
	for (i=0; i<4; i++) {
		if (tot>0) {
			av[i]/=tot;
			rms[i]/=tot;
		}
		rms[i] -= av[i]*av[i];
		if (rms[i]<0) fprintf(stderr,"Due to precision, negative RMS in routine %d\n",i);
		else rms[i] = sqrt(rms[i]);
		fprintf(stdout,"routine %d, average %e, rms %e\n",i,av[i],rms[i]);
	}
	powercount();
}

