use crate::UBigInt;
impl UBigInt {
#[must_use = "method returns a new number and does not mutate the original value"]
pub fn shift_right(&self, n: usize) -> Self {
if n >= self.len() {
UBigInt::zero()
}
else {
UBigInt::from_raw(self.0[n..].to_vec())
}
}
pub fn shift_right_mut(&mut self, n: usize) {
if n >= self.len() {
self.0 = vec![0];
}
else {
self.0 = self.0[n..].to_vec();
}
}
#[must_use = "method returns a new number and does not mutate the original value"]
pub fn shift_left(&self, n: usize) -> Self {
if self.is_zero() {
UBigInt::zero()
}
else {
UBigInt::from_raw(vec![
vec![0; n],
self.0.clone()
].concat())
}
}
pub fn shift_left_mut(&mut self, n: usize) {
if !self.is_zero() {
self.0 = vec![
vec![0; n],
self.0.clone()
].concat();
}
}
#[must_use = "method returns a new number and does not mutate the original value"]
pub fn slice_right(&self, n: usize) -> Self {
if n == 0 {
UBigInt::zero()
}
else {
let mut result = self.0[0..n].to_vec();
while result.len() > 1 && result[result.len() - 1] == 0 {
result.pop().unwrap();
}
UBigInt::from_raw(result)
}
}
pub fn slice_right_mut(&mut self, n: usize) {
if n == 0 {
*self = UBigInt::zero();
}
else {
let mut result = self.0[0..n].to_vec();
while result.len() > 1 && result[result.len() - 1] == 0 {
result.pop().unwrap();
}
self.0 = result;
}
}
}