Module malachite_base::num::arithmetic::div_round
source · Expand description
DivRound
and DivExactAssign
, traits for
dividing two numbers according to a specified
RoundingMode
.
§div_round
use malachite_base::num::arithmetic::traits::DivRound;
use malachite_base::rounding_modes::RoundingMode::*;
use std::cmp::Ordering::*;
assert_eq!(10u8.div_round(4, Down), (2, Less));
assert_eq!(10u16.div_round(4, Up), (3, Greater));
assert_eq!(10u32.div_round(5, Exact), (2, Equal));
assert_eq!(10u64.div_round(3, Nearest), (3, Less));
assert_eq!(20u128.div_round(3, Nearest), (7, Greater));
assert_eq!(10usize.div_round(4, Nearest), (2, Less));
assert_eq!(14u8.div_round(4, Nearest), (4, Greater));
assert_eq!((-10i8).div_round(4, Down), (-2, Greater));
assert_eq!((-10i16).div_round(4, Up), (-3, Less));
assert_eq!((-10i32).div_round(5, Exact), (-2, Equal));
assert_eq!((-10i64).div_round(3, Nearest), (-3, Greater));
assert_eq!((-20i128).div_round(3, Nearest), (-7, Less));
assert_eq!((-10isize).div_round(4, Nearest), (-2, Greater));
assert_eq!((-14i8).div_round(4, Nearest), (-4, Less));
assert_eq!((-10i16).div_round(-4, Down), (2, Less));
assert_eq!((-10i32).div_round(-4, Up), (3, Greater));
assert_eq!((-10i64).div_round(-5, Exact), (2, Equal));
assert_eq!((-10i128).div_round(-3, Nearest), (3, Less));
assert_eq!((-20isize).div_round(-3, Nearest), (7, Greater));
assert_eq!((-10i8).div_round(-4, Nearest), (2, Less));
assert_eq!((-14i16).div_round(-4, Nearest), (4, Greater));
§div_round_assign
use malachite_base::num::arithmetic::traits::DivRoundAssign;
use malachite_base::rounding_modes::RoundingMode::*;
use std::cmp::Ordering::*;
let mut x = 10u8;
assert_eq!(x.div_round_assign(4, Down), Less);
assert_eq!(x, 2);
let mut x = 10u16;
assert_eq!(x.div_round_assign(4, Up), Greater);
assert_eq!(x, 3);
let mut x = 10u32;
assert_eq!(x.div_round_assign(5, Exact), Equal);
assert_eq!(x, 2);
let mut x = 10u64;
assert_eq!(x.div_round_assign(3, Nearest), Less);
assert_eq!(x, 3);
let mut x = 20u128;
assert_eq!(x.div_round_assign(3, Nearest), Greater);
assert_eq!(x, 7);
let mut x = 10usize;
assert_eq!(x.div_round_assign(4, Nearest), Less);
assert_eq!(x, 2);
let mut x = 14u8;
assert_eq!(x.div_round_assign(4, Nearest), Greater);
assert_eq!(x, 4);
let mut x = -10i8;
assert_eq!(x.div_round_assign(4, Down), Greater);
assert_eq!(x, -2);
let mut x = -10i16;
assert_eq!(x.div_round_assign(4, Up), Less);
assert_eq!(x, -3);
let mut x = -10i32;
assert_eq!(x.div_round_assign(5, Exact), Equal);
assert_eq!(x, -2);
let mut x = -10i64;
assert_eq!(x.div_round_assign(3, Nearest), Greater);
assert_eq!(x, -3);
let mut x = -20i128;
assert_eq!(x.div_round_assign(3, Nearest), Less);
assert_eq!(x, -7);
let mut x = -10isize;
assert_eq!(x.div_round_assign(4, Nearest), Greater);
assert_eq!(x, -2);
let mut x = -14i8;
assert_eq!(x.div_round_assign(4, Nearest), Less);
assert_eq!(x, -4);
let mut x = -10i16;
assert_eq!(x.div_round_assign(-4, Down), Less);
assert_eq!(x, 2);
let mut x = -10i32;
assert_eq!(x.div_round_assign(-4, Up), Greater);
assert_eq!(x, 3);
let mut x = -10i64;
assert_eq!(x.div_round_assign(-5, Exact), Equal);
assert_eq!(x, 2);
let mut x = -10i128;
assert_eq!(x.div_round_assign(-3, Nearest), Less);
assert_eq!(x, 3);
let mut x = -20isize;
assert_eq!(x.div_round_assign(-3, Nearest), Greater);
assert_eq!(x, 7);
let mut x = -10i8;
assert_eq!(x.div_round_assign(-4, Nearest), Less);
assert_eq!(x, 2);
let mut x = -14i16;
assert_eq!(x.div_round_assign(-4, Nearest), Greater);
assert_eq!(x, 4);