2017-10-12 19:30:00 +00:00
|
|
|
use num::Num;
|
2016-07-02 07:47:38 +00:00
|
|
|
|
2017-10-12 19:30:00 +00:00
|
|
|
/// Integer division that rounds up.
|
|
|
|
pub fn div_up<T>(p: T, q: T) -> T
|
|
|
|
where
|
|
|
|
T: Num + Clone,
|
|
|
|
{
|
|
|
|
let d = p.clone() / q.clone();
|
|
|
|
|
|
|
|
if p % q == T::zero() {
|
|
|
|
d
|
|
|
|
} else {
|
|
|
|
T::one() + d
|
|
|
|
}
|
|
|
|
}
|