const_primes

Function previous_prime

Source
pub const fn previous_prime(n: u64) -> Option<u64>
Expand description

Returns the largest prime smaller than n if there is one.

Scans for primes downwards from the input with is_prime.

§Examples

Basic usage:

const PREV: Option<u64> = previous_prime(400);
assert_eq!(PREV, Some(397));

There’s no prime smaller than two:

const NO_SUCH: Option<u64> = previous_prime(2);
assert_eq!(NO_SUCH, None);