#ifndef TRIG_HPP



// TRIG_HPP

#define TRIG_HPP

#include

#define DEPTH 8

namespace mt

{

const long double PI = 3.14159265358979323f;

// FACTORIAL

template struct fact

{

static const long long value = N * fact::value;

};

template struct fact

{

static const long long value = 1L;

};

// EXPONENTS

template struct power

{

static const long double value;

};

template const long double power::value

= X::value * power::value;

template struct power

{

static const long double value;

};

template const long double power::value = 1.0f;

// SIMPLIFY RADIAN TO INTERVAL [-2π, 2π]

template struct SimplifyRad

{

static const long double value;

};

template const long double SimplifyRad::value =

X::value - (2 * PI * (double) (int) (X::value/(2*PI))); // float modulo?

// COSINE

template struct cos

{

static const long double value;

};

template const long double cos::value =

(((N % 2 == 0 ? 1 : -1) * power::value) / ((long double)

fact::value)) + cos::value;

template struct cos

{

static const long double value;

};

template const long double cos::value = 1.0f;

// SINE

template struct sin

{

static const long double value;

};

template const long double sin::value =

(((N % 2 == 0 ? -1 : 1) * power::value) / ((long double)

fact::value)) + sin::value;

template struct sin

{

static const long double value;

};

template const long double sin::value = 0.0f;

// TANGENT

template struct tan

{

static const long double value;

};

template const long double tan::value = sin::value /

cos::value;

}

#endif

struct var

{

static const long double value;

};

const long double var::value = mt::PI / 4;

int main(int argc, char *argv[])

{

printf("%Lf\n", var::value);

printf("sin(%Lf) = %Lf\ncos(%Lf) = %Lf\ntan(%Lf) = %Lf\n",

var::value, mt::sin::value,

var::value, mt::cos::value,

var::value, mt::tan::value);

}

0.785398

sin(0.785398) = 0.707107

cos(0.785398) = 0.707107

tan(0.785398) = 1.000000

//Todd Veldhuizen

//

#define M_PI 3.141596

#include

#include

using namespace std;

// Compute J terms in the series expansion. K is the loop variable.

template

class SineSeries {

public:

enum { go = (K+1 != J) };

static inline float accumulate()

{

return 1-(I*2*M_PI/N)*(I*2*M_PI/N)/(2*K+2)/(2*K+3) *

SineSeries::accumulate();

}

};

// Specialization to terminate loop

template class SineSeries {

public:

static inline float accumulate()

{ return 1; }

};

template

class Sine {

public:

static inline float sin()

{

return (I*2*M_PI/N) * SineSeries::accumulate();

}

};

int main()

{

float f = Sine::sin();

cout ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download