Method: Prime::TrialDivision#initialize

Defined in:
lib/prime.rb

#initializeTrialDivision

:nodoc:



479
480
481
482
483
484
485
486
487
488
489
490
# File 'lib/prime.rb', line 479

def initialize # :nodoc:
  # These are included as class variables to cache them for later uses.  If memory
  #   usage is a problem, they can be put in Prime#initialize as instance variables.

  # There must be no primes between @primes[-1] and @next_to_check.
  @primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101]
  # @next_to_check % 6 must be 1.
  @next_to_check = 103            # @primes[-1] - @primes[-1] % 6 + 7
  @ulticheck_index = 3            # @primes.index(@primes.reverse.find {|n|
  #   n < Math.sqrt(@@next_to_check) })
  @ulticheck_next_squared = 121   # @primes[@ulticheck_index + 1] ** 2
end