1 // This is a part of Chrono.
2 // Portions Copyright 2013-2014 The Rust Project Developers.
3 // See README.md and LICENSE.txt for details.
4 
5 //! Integer division utilities. (Shamelessly copied from [num](https://github.com/rust-lang/num/))
6 
7 // Algorithm from [Daan Leijen. _Division and Modulus for Computer Scientists_,
8 // December 2001](http://research.microsoft.com/pubs/151917/divmodnote-letter.pdf)
9 
10 pub use num_integer::{div_floor, div_mod_floor, div_rem, mod_floor};
11 
12 #[cfg(test)]
13 mod tests {
14     use super::{div_mod_floor, mod_floor};
15 
16     #[test]
test_mod_floor()17     fn test_mod_floor() {
18         assert_eq!(mod_floor(8, 3), 2);
19         assert_eq!(mod_floor(8, -3), -1);
20         assert_eq!(mod_floor(-8, 3), 1);
21         assert_eq!(mod_floor(-8, -3), -2);
22 
23         assert_eq!(mod_floor(1, 2), 1);
24         assert_eq!(mod_floor(1, -2), -1);
25         assert_eq!(mod_floor(-1, 2), 1);
26         assert_eq!(mod_floor(-1, -2), -1);
27     }
28 
29     #[test]
test_div_mod_floor()30     fn test_div_mod_floor() {
31         assert_eq!(div_mod_floor(8, 3), (2, 2));
32         assert_eq!(div_mod_floor(8, -3), (-3, -1));
33         assert_eq!(div_mod_floor(-8, 3), (-3, 1));
34         assert_eq!(div_mod_floor(-8, -3), (2, -2));
35 
36         assert_eq!(div_mod_floor(1, 2), (0, 1));
37         assert_eq!(div_mod_floor(1, -2), (-1, -1));
38         assert_eq!(div_mod_floor(-1, 2), (-1, 1));
39         assert_eq!(div_mod_floor(-1, -2), (0, -1));
40     }
41 }
42