Skip to content

Commit

Permalink
Simplify calculation of mem_sqr in sieving functions
Browse files Browse the repository at this point in the history
  • Loading branch information
JSorngard committed May 10, 2024
1 parent b44fa9d commit c417e0e
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/sieving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,10 @@ pub const fn sieve_lt<const N: usize, const MEM: usize>(
assert!(N > 0, "`N` must be at least 1");
assert!(MEM >= N, "`MEM` must be at least as large as `N`");

let mem_sqr = {
let mem64 = MEM as u64;
match mem64.checked_mul(mem64) {
Some(prod) => prod,
None => panic!("`MEM`^2 must fit in a `u64`"),
}
let mem64 = MEM as u64;

let Some(mem_sqr) = mem64.checked_mul(mem64) else {
panic!("`MEM`^2 must fit in a `u64`");
};

if upper_limit > mem_sqr {
Expand Down Expand Up @@ -307,12 +305,10 @@ pub const fn sieve_geq<const N: usize, const MEM: usize>(
assert!(N > 0, "`N` must be at least 1");
assert!(MEM >= N, "`MEM` must be at least as large as `N`");

let (mem64, mem_sqr) = {
let mem64 = MEM as u64;
match mem64.checked_mul(mem64) {
Some(prod) => (mem64, prod),
None => panic!("`MEM`^2 must fit in a `u64`"),
}
let mem64 = MEM as u64;

let Some(mem_sqr) = mem64.checked_mul(mem64) else {
panic!("`MEM`^2 must fit in a `u64`");
};

let Some(upper_limit) = mem64.checked_add(lower_limit) else {
Expand Down

0 comments on commit c417e0e

Please sign in to comment.