macro_rules! primes_segment {
($n:expr; < $lim:expr) => { ... };
($n:expr; >= $lim:expr) => { ... };
}
Expand description
Generate arrays of large prime numbers without having to store all primes from 2 and up in the result, and thus potentially the binary.
Calls primes_geq
or primes_lt
, and automatically computes the memory requirement of the sieve.
Compute N
primes larger than or equal to some limit as primes_segment!(N; >= LIMIT)
,
and N
primes less than some limit as primes_segment!(N; < LIMIT)
.
Estimates the sieve size as isqrt(upper_limit) + 1
for primes_lt
and as isqrt(lower_limit) + 1 + N
for primes_geq
.
This may overestimate the memory requirement for primes_geq
.
§Example
const N: usize = 3;
const LIMIT: u64 = 5_000_000_031;
const PRIMES_GEQ: Result<[u64; N], GenerationError> = primes_segment!(N; >= LIMIT);
const PRIMES_LT: Result<[u64; N], GenerationError> = primes_segment!(N; < LIMIT);
// Can also be used at runtime:
let primes_geq = primes_segment!(N; >= LIMIT);
assert_eq!(PRIMES_GEQ, primes_geq);
assert_eq!(PRIMES_GEQ, Ok([5000000039, 5000000059, 5000000063]));
assert_eq!(PRIMES_LT, Ok([4999999903, 4999999937, 5000000029]));
§Errors
Has the same error behaviour as primes_geq
and primes_lt
, with the exception
that it sets MEM
such that the sieve doesn’t run out of memory.