Skip to main content

Module shr

Module shr 

Source
Expand description

Right-shifting a vector (dividing it by a power of 2 and taking the floor), by implementations of Shr and ShrAssign.

§shr

use core::str::FromStr;
use malachite_nz::integer_vector::IntegerVector;

assert_eq!(
    (IntegerVector::from_str("()").unwrap() >> 10u8).to_string(),
    "()"
);
assert_eq!(
    (IntegerVector::from_str("(1, -2, 3)").unwrap() >> 0u16).to_string(),
    "(1, -2, 3)"
);
assert_eq!(
    (IntegerVector::from_str("(4, -8, 12)").unwrap() >> 2u32).to_string(),
    "(1, -2, 3)"
);
assert_eq!(
    (IntegerVector::from_str("(-1, 2, -3, 5)").unwrap() >> 1u8).to_string(),
    "(-1, 1, -2, 2)"
);
assert_eq!(
    (&IntegerVector::from_str("(-3802951800684688204490109616128, 0)").unwrap() >> 100u64)
        .to_string(),
    "(-3, 0)"
);
assert_eq!(
    (IntegerVector::from_str("(1, -2, 3)").unwrap() >> -2i8).to_string(),
    "(4, -8, 12)"
);
assert_eq!(
    (&IntegerVector::from_str("(-1, 2, -3, 5)").unwrap() >> 1i64).to_string(),
    "(-1, 1, -2, 2)"
);

§shr_assign

use core::str::FromStr;
use malachite_nz::integer_vector::IntegerVector;

let mut v = IntegerVector::from_str("(-1, 2, -3, 5)").unwrap();
v >>= 1u32;
assert_eq!(v.to_string(), "(-1, 1, -2, 2)");
let mut v = IntegerVector::from_str("(1, -2, 3)").unwrap();
v >>= -2i32;
assert_eq!(v.to_string(), "(4, -8, 12)");