File: div.rs

package info (click to toggle)
rust-cursive-core 0.4.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,316 kB
  • sloc: makefile: 2
file content (15 lines) | stat: -rw-r--r-- 230 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use num::Num;

/// 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
    }
}