/** * constructs the tables from the static parameters */ public static void constructTables() { tables = new SinCosTable[numTables]; Console.WriteLine("constructing tables"); for (int i = 0; i < numTables; i++) { // well... basic lerp float precision = i*1f/numTables*(leastPreciseTable - mostPreciseTable) + mostPreciseTable; tables[i] = new SinCosTable(precision); } }
private static long speedTest(SinCosTable table, int numIterations, int numTrials) { long startTime, endTime; long totalTime = 0; float i, j; float k = 0; float jstep = MathUtils.TWOPI/numIterations; for (i = 0; i < numTrials; i++) { startTime = Stopwatch.GetTimestamp(); for (j = 0; j < MathUtils.TWOPI; j += jstep) { k += table.sin(j); } endTime = Stopwatch.GetTimestamp(); totalTime += endTime - startTime; } i += k; return numIterations*numTrials*1000000000L/(totalTime); }
private static double accuracyTest(SinCosTable table, int iterations) { double totalDiff = 0f, diff = 0f; for (int i = 0; i < iterations; i++) { float querry = (float) _random.NextDouble()*MathUtils.TWOPI; diff = MathUtils.abs((float) System.Math.Sin(querry) - table.sin(querry)); totalDiff += diff; } totalDiff /= iterations; return totalDiff; }