Skip to content

Commit 2c5f1f9

Browse files
xtqqczzesylvestre
authored andcommitted
polyfill div_ceil
1 parent 4f4110d commit 2c5f1f9

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/buffer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,8 @@ impl NaiveBuffer {
427427
/// Legendre's phi function, used as a helper function for [`Self::prime_pi`]
428428
pub fn prime_phi(&mut self, x: u64, a: usize, cache: &mut LruCache<(u64, usize), u64>) -> u64 {
429429
if a == 1 {
430-
return (x + 1) / 2;
430+
// TODO(MSRV>=1.73): feature(int_roundings1): use div_ceil
431+
return crate::util::div_ceil_u64(x, 2);
431432
}
432433
if let Some(v) = cache.get(&(x, a)) {
433434
return *v;

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ mod primality;
7474
mod rand;
7575
mod tables;
7676
mod traits;
77+
mod util;
7778

7879
pub use traits::*;
7980
pub mod detail {

src/util.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pub const fn div_ceil_u64(lhs: u64, rhs: u64) -> u64 {
2+
let d = lhs / rhs;
3+
let r = lhs % rhs;
4+
if r > 0 {
5+
d + 1
6+
} else {
7+
d
8+
}
9+
}

0 commit comments

Comments
 (0)