/*
 @Author Erikd
 **/
public class FastTrig{

  public static int PRECISION = 0x100000;

  public static final float PI    = (float)java.lang.Math.PI,
                            PI_2  = PI*2;

  private static float RAD_SLICE  = PI_2 / PRECISION,
                       sinTable[] = null,
                       cosTable[] = null,
                       tanTable[] = null;

  static {

    RAD_SLICE = PI_2 / PRECISION;
    sinTable  = new float[PRECISION];
    cosTable  = new float[PRECISION];
    tanTable  = new float[PRECISION];
    float rad = 0;

    for (int i = 0; i < PRECISION; i++) {
      rad         = (float)i * RAD_SLICE;
      sinTable[i] = (float)java.lang.Math.sin(rad);
      cosTable[i] = (float)java.lang.Math.cos(rad);
      tanTable[i] = (float)java.lang.Math.tan(rad);
    }
  }

  private static final int radToIndex(float radians) {
    return (int)((radians / PI_2) * (float)PRECISION) & (PRECISION-1);
  }

  public static float sin(float radians) {
   return sinTable[radToIndex(radians)];
  }

  public static float cos(float radians) {
   return cosTable[radToIndex(radians)];
  }

  public static float tan(float radians) {
    return tanTable[radToIndex(radians)];
  }
}

