Skip to main content

Module entrywise_div_round

Module entrywise_div_round 

Source
Expand description

Dividing every element of a vector by a scalar and rounding each quotient, by implementations of EntrywiseDivRound and EntrywiseDivRoundAssign.

§entrywise_div_round

use core::str::FromStr;
use malachite_base::num::arithmetic::traits::EntrywiseDivRound;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_base::unsigned_vector::UnsignedVector;

assert_eq!(
    UnsignedVector::<u8>::from_str("(1, 2, 3, 5)")
        .unwrap()
        .entrywise_div_round(2u8, Floor)
        .to_string(),
    "(0, 1, 1, 2)"
);
assert_eq!(
    (&UnsignedVector::<u8>::from_str("(1, 2, 3, 5)").unwrap())
        .entrywise_div_round(2u8, Ceiling)
        .to_string(),
    "(1, 1, 2, 3)"
);
assert_eq!(
    (&UnsignedVector::<u8>::from_str("(1, 2, 3, 5)").unwrap())
        .entrywise_div_round(2u8, Nearest)
        .to_string(),
    "(0, 1, 2, 2)"
);
assert_eq!(
    UnsignedVector::<u8>::from_str("(3, 6, 255)")
        .unwrap()
        .entrywise_div_round(3u8, Exact)
        .to_string(),
    "(1, 2, 85)"
);

§entrywise_div_round_assign

use core::str::FromStr;
use malachite_base::num::arithmetic::traits::EntrywiseDivRoundAssign;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_base::unsigned_vector::UnsignedVector;

let mut v = UnsignedVector::<u8>::from_str("(1, 2, 3, 5)").unwrap();
v.entrywise_div_round_assign(2u8, Nearest);
assert_eq!(v.to_string(), "(0, 1, 2, 2)");