is_prime

Function is_prime 

Source
pub fn is_prime(number: u32) -> bool
Expand description

Checks whether a number is prime, using optimized trial division.

This approach checks only odd numbers starting from 3 and up to the square root of the given number. This is based on the fact that if a number is divisible by a number larger than its square root, the result of the division will be smaller than the square root, and it would have already been checked in previous iterations.

ยงExamples

use numera::all::is_prime;

assert![is_prime(13)];
assert![!is_prime(8)];