/*
* First, compile-time trig functions sin(x) and cos(x).
*/
template<unsigned N, unsigned I>
class Sine {
public:
static inline float sin()
{
// This is a series expansion for sin(I*2*M_PI/N)
// Since all of these quantities are known at compile time, it gets
// simplified to a single constant, which can be included in the code:
// mov dword ptr es:[bx],large 03F3504F3h
template<unsigned N, unsigned I>
class Cosine {
public:
static inline float cos()
{
// This is a series expansion for cos(I*2*M_PI/N)
// Since all of these quantities are known at compile time, it gets
// simplified to a single number.
return 1-(I*2*M_PI/N)*(I*2*M_PI/N)/2*(1-(I*2*M_PI/N)*(I*2*M_PI/N)/3/4*
(1-(I*2*M_PI/N)*(I*2*M_PI/N)/5/6*(1-(I*2*M_PI/N)*(I*2*M_PI/N)/7/8*
(1-(I*2*M_PI/N)*(I*2*M_PI/N)/9/10*(1-(I*2*M_PI/N)*(I*2*M_PI/N)/11/12*
(1-(I*2*M_PI/N)*(I*2*M_PI/N)/13/14*(1-(I*2*M_PI/N)*(I*2*M_PI/N)/15/16*
(1-(I*2*M_PI/N)*(I*2*M_PI/N)/17/18*(1-(I*2*M_PI/N)*(I*2*M_PI/N)/19/20*
(1-(I*2*M_PI/N)*(I*2*M_PI/N)/21/22*(1-(I*2*M_PI/N)*(I*2*M_PI/N)/23/24
)))))))))));
}