bitcode/nightly.rs
1/// `#![feature(int_roundings)]` was stabilized in 1.73, but we want to avoid MSRV that high.
2macro_rules! impl_div_ceil {
3 ($name:ident, $t:ty) => {
4 #[inline(always)]
5 #[allow(unused_comparisons)] // < 0 checks not required for unsigned
6 pub const fn $name(lhs: $t, rhs: $t) -> $t {
7 let d = lhs / rhs;
8 let r = lhs % rhs;
9 if (r > 0 && rhs > 0) || (r < 0 && rhs < 0) {
10 d + 1
11 } else {
12 d
13 }
14 }
15 };
16}
17impl_div_ceil!(div_ceil_u8, u8);
18impl_div_ceil!(div_ceil_usize, usize);