protected static void statistics ( int from , int to ) { // check that primes contain no accidental errors for ( int i = 0 ; i < primeCapacities . length - 1 ; i ++ ) { if ( primeCapacities [ i ] >= primeCapacities [ i + 1 ] ) throw new RuntimeException ( "primes are unsorted or contain duplicates; detected at " + i + "@" + primeCapacities [ i ] ) ; } double accDeviation = 0.0 ; double maxDeviation = - 1.0 ; for ( int i = from ; i <= to ; i ++ ) { int primeCapacity = nextPrime ( i ) ; //System.out.println(primeCapacity); double deviation = ( primeCapacity - i ) / ( double ) i ; if ( deviation > maxDeviation ) { maxDeviation = deviation ; System . out . println ( "new maxdev @" + i + "@dev=" + maxDeviation ) ; } accDeviation += deviation ; } long width = 1 + ( long ) to - ( long ) from ; double meanDeviation = accDeviation / width ; System . out . println ( "Statistics for [" + from + "," + to + "] are as follows" ) ; System . out . println ( "meanDeviation = " + ( float ) meanDeviation * 100 + " %" ) ; System . out . println ( "maxDeviation = " + ( float ) maxDeviation * 100 + " %" ) ; }
Tests correctness .