flatty_base/utils/
mod.rs

1#[cfg(feature = "alloc")]
2pub mod alloc;
3pub mod iter;
4pub mod mem;
5
6/// `const` version of [`usize::max`].
7pub const fn max(a: usize, b: usize) -> usize {
8    if a >= b {
9        a
10    } else {
11        b
12    }
13}
14
15/// `const` version of [`usize::min`].
16pub const fn min(a: usize, b: usize) -> usize {
17    if a <= b {
18        a
19    } else {
20        b
21    }
22}
23
24/// Smallest number that is both greater or equal to `x` and a multiple of `m`.
25pub const fn ceil_mul(x: usize, m: usize) -> usize {
26    ((x + m - 1) / m) * m
27}
28
29/// Biggest number that is both lower or equal to `x` and a multiple of `m`.
30pub const fn floor_mul(x: usize, m: usize) -> usize {
31    (x / m) * m
32}