Module malachite_base::num::arithmetic::shl_round

source ·
Expand description

ShlRound and ShlRoundAssign, traits for multiplying a number by a power of 2 and rounding according to a specified RoundingMode.

§shl_round

use malachite_base::num::arithmetic::traits::ShlRound;
use malachite_base::rounding_modes::RoundingMode::*;
use std::cmp::Ordering::*;

assert_eq!(0x101u16.shl_round(-8i8, Down), (1, Less));
assert_eq!(0x101u32.shl_round(-8i16, Up), (2, Greater));

assert_eq!((-0x101i16).shl_round(-9i32, Down), (0, Greater));
assert_eq!((-0x101i32).shl_round(-9i64, Up), (-1, Less));
assert_eq!((-0x101i64).shl_round(-9i8, Nearest), (-1, Less));
assert_eq!((-0xffi32).shl_round(-9i16, Nearest), (0, Greater));
assert_eq!((-0x100i16).shl_round(-9i32, Nearest), (0, Greater));

assert_eq!(0x100u64.shl_round(-8i64, Exact), (1, Equal));

§shl_round_assign

use malachite_base::num::arithmetic::traits::ShlRoundAssign;
use malachite_base::rounding_modes::RoundingMode::*;
use std::cmp::Ordering::*;

let mut x = 0x101u16;
assert_eq!(x.shl_round_assign(-8i8, Down), Less);
assert_eq!(x, 1);

let mut x = 0x101u32;
assert_eq!(x.shl_round_assign(-8i16, Up), Greater);
assert_eq!(x, 2);

let mut x = -0x101i16;
assert_eq!(x.shl_round_assign(-9i32, Down), Greater);
assert_eq!(x, 0);

let mut x = -0x101i32;
assert_eq!(x.shl_round_assign(-9i64, Up), Less);
assert_eq!(x, -1);

let mut x = -0x101i64;
assert_eq!(x.shl_round_assign(-9i8, Nearest), Less);
assert_eq!(x, -1);

let mut x = -0xffi32;
assert_eq!(x.shl_round_assign(-9i16, Nearest), Greater);
assert_eq!(x, 0);

let mut x = -0x100i16;
assert_eq!(x.shl_round_assign(-9i32, Nearest), Greater);
assert_eq!(x, 0);

let mut x = 0x100u64;
assert_eq!(x.shl_round_assign(-8i64, Exact), Equal);
assert_eq!(x, 1);