#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <malloc.h>
#include "Exception.h"
#include "MathP.h"
#include "Chebyshev.h"

int main(int argc, char **argv)
{
  if (argc != 3) {
    fprintf(stderr, "usage: %s angle nCoeffs\n", argv[0]);
    return -1;
  }

  double degrees = atof(argv[1]);
  double x = Math::RadsPerDeg * degrees;

  double lower = 0.;
  double upper = 90. * Math::RadsPerDeg;
  int nCoeffs = atoi(argv[2]);

  Chebyshev cosine(lower, upper, nCoeffs, cos);
  Chebyshev sine(lower, upper, nCoeffs, sin);

  try {

    printf("sine %.3f: library = %.5f, chebyshev = %.5f\n",
	   degrees, sin(x), sine.evaluate(x));

    printf("cosine %.3f: library = %.5f, chebyshev = %.5f\n",
	   degrees, cos(x), cosine.evaluate(x));

  }
  catch (Exception e) {
    fprintf(stderr, "Caught exception: %s\n", e.msg);
  }

  return 0;
}

