ctprimes

This module provides arrays of prime numbers that are available at compile-time. Arrays are calculated as long as you need, using CTFE.

This module uses the Sieve of Eratosthenes to find primes and so is reasonably performant, but care should be taken with memory usage. For example, with dmd without -lowmem, an array of only 26k primes will cost 3 GB of memory during compilation.

Members

Functions

composites
bool[] composites(size_t length)
Undocumented in source. Be warned that the author may not have intended to support it.
nth_prime_upper_bound
size_t nth_prime_upper_bound(size_t n)
Undocumented in source. Be warned that the author may not have intended to support it.

Templates

ctPrimes
template ctPrimes(size_t length, T = size_t)

Construct an array of prime number using CTFE. The length of the array is length, and the type is T[length].

ctPrimesLessThan
template ctPrimesLessThan(alias N)

Construct an array of all prime numbers less than N, using CTFE. The type of the array is typeof(N)[].

Meta