1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use crate::natural::InnerNatural::{Large, Small};
use crate::natural::Natural;
use crate::platform::Limb;
use malachite_base::num::arithmetic::traits::{ModPowerOf2Assign, ShrRound};
use malachite_base::num::basic::integers::PrimitiveInt;
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_base::num::logic::traits::LowMask;
use malachite_base::rounding_modes::RoundingMode;
pub_crate_test! {limbs_low_mask(bits: u64) -> Vec<Limb> {
let len = bits.shr_round(Limb::LOG_WIDTH, RoundingMode::Ceiling);
let remaining_bits = bits & Limb::WIDTH_MASK;
let mut xs = vec![Limb::MAX; usize::exact_from(len)];
if remaining_bits != 0 {
xs.last_mut().unwrap().mod_power_of_2_assign(remaining_bits);
}
xs
}}
impl LowMask for Natural {
fn low_mask(bits: u64) -> Natural {
if bits <= Limb::WIDTH {
Natural(Small(Limb::low_mask(bits)))
} else {
Natural(Large(limbs_low_mask(bits)))
}
}
}