?

Log in

No account? Create an account
chris/CO149
co149
.:::: .. .:.. .:: .:: ::. ::::..:: :..::.

November 2010
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

chris/CO149 [userpic]
How I spend my time

#include <stdio.h>

#define DIVISIONS 4096

double S[DIVISIONS+1], C[DIVISIONS+1], T[DIVISIONS+1];

void avang(int a, int b);
double squareroot(double x);

int main(void)
{
  int i;

  S[0] = 0.0;
  C[0] = 1.0;
  T[0] = 0.0;
  S[DIVISIONS] = 1.0;
  C[DIVISIONS] = 0.0;
  T[DIVISIONS] = 1.0 / 0.0;

  avang(0, DIVISIONS);

  printf(" x     sin x     cos x     tan x\n");
  printf("----  --------  --------  --------\n");
  for(i = 0; i <= DIVISIONS; i++)
  {
    printf("%4.4d  %8.6lf  %8.6lf  %8.6lf\n",
           i,
           S[i],
           C[i],
           T[i]);
  }
}

void avang(int a, int b)
{
  int c;
  double ma, mb, pa, pb;

  ma = squareroot((1.0 - C[a]) / 2.0);
  mb = squareroot((1.0 - C[b]) / 2.0);
  pa = squareroot((1.0 + C[a]) / 2.0);
  pb = squareroot((1.0 + C[b]) / 2.0);

  c = (a + b) / 2;

  S[c] = ma * pb + pa * mb;
  C[c] = pa * pb - ma * mb;
  T[c] = S[c] / C[c];

  if (c % 2 == 0)
  {
    avang(a,c);
    avang(c,b);
  }
}

double squareroot(double q)
{
#define EPSILON 1.0e-13
  double x, x1;

  if (q < EPSILON) return 0;

  x1 =  q / 2.0;
  do {
    x = x1;
    x1 = x - (x * x - q) / (2.0 * x);
  } while ((x - x1) * (x - x1) > (EPSILON * EPSILON));

  return x1;
}


(HELP!!!)

Comments
(no subject) - (Anonymous)

It wasn't a mistake, but *shhhh*! I wish I could give some volunteer time, but my work schedule sucks. Oh well.

Three members of Grave Danger (that I know of) are friends from before the league formed, and I'm a Big Fan :-)

much love
chris