Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 22nd, 2012  |  syntax: None  |  size: 0.94 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. MathTest.java:
  2.  
  3.  
  4. import java.util.concurrent.Callable;
  5.  
  6. import bb.util.Benchmark;
  7.  
  8. public class MathTest {
  9.         protected static double sin() {
  10.                 float a = 0.0f;
  11.                 for (float i = (float)-Math.PI * 2; i < Math.PI * 2; i += 0.001f) {
  12.                         a += MathHelper.sin(i);
  13.                         //a += Math.sin(i);
  14.                 }
  15.                 return a;
  16.         }
  17.  
  18.         public static void main(String[] args) throws Exception {
  19.                 Callable<Double> task = new Callable<Double>() { public Double call() { return sin(); } };
  20.                 System.out.println("MathHelper.sin(): " + new Benchmark(task));
  21.         }
  22. }
  23.  
  24.  
  25. MathHelper.java:
  26.  
  27.  
  28.  
  29. public class MathHelper
  30. {
  31.     private static float[] SIN_TABLE = new float[1024];
  32.  
  33.     public static final float sin(float par0)
  34.     {
  35.         return SIN_TABLE[(int)(par0 * 10430.378F) & 1023];
  36.     }
  37.  
  38.     static
  39.     {
  40.         for (int var0 = 0; var0 < 1024; ++var0)
  41.         {
  42.             SIN_TABLE[var0] = (float)Math.sin((double)var0 * Math.PI * 2.0D / 1024.0D);
  43.         }
  44.     }
  45. }