#include "fastmath.h"

unsigned int fast_sqrt_table[0x10000];  // declare table of square roots 

void build_sqrt_table(void)
{
  unsigned int i;
  FastSqrtUnion s;
  
  for (i = 0; i <= 0x7FFF; i++)
  {
    
    // Build a float with the bit pattern i as mantissa
    //  and an exponent of 0, stored as 127
    
    s.i = (i << 8) | (0x7F << 23);
    s.f = (float)sqrt(s.f);
    
    // Take the square root then strip the first 7 bits of
    //  the mantissa into the table
    
    fast_sqrt_table[i + 0x8000] = (s.i & 0x7FFFFF);
    
    // Repeat the process, this time with an exponent of 1, 
    //  stored as 128
    
    s.i = (i << 8) | (0x80 << 23);
    s.f = (float)sqrt(s.f);
    
    fast_sqrt_table[i] = (s.i & 0x7FFFFF);
  }
}

float g_sint[4096];
float g_cost[4096];

void build_sin_table(void)
{
	for(int k=0;k<4096;k++)
	{
		float r = sin(k*D3DX_PI/2048.f);
		g_sint[k] = (r *10000000.f - (r * 10000000.f-((int)(r *10000000))))/10000000.f;
		r = cos(k*D3DX_PI/2048.f);
		g_cost[k] = (r *10000000.f - (r * 10000000.f-((int)(r *10000000))))/10000000.f;
	}
}