This commit is contained in:
parent
a8de0cfa88
commit
9f60706a9b
@ -142,6 +142,7 @@ impl Sub for BigInt {
|
||||
type Output = Self;
|
||||
|
||||
fn sub(self, rhs: Self) -> Self::Output {
|
||||
// @TODO: handle signs
|
||||
let mut out = BigInt::new_empty();
|
||||
|
||||
let u_digits = self.inner.len();
|
||||
@ -158,10 +159,6 @@ impl Sub for BigInt {
|
||||
let a = *self.inner.get(i).unwrap_or(&0usize);
|
||||
let b = *rhs.inner.get(i).unwrap_or(&0usize);
|
||||
|
||||
if a == 0 && b == 0 {
|
||||
continue;
|
||||
}
|
||||
|
||||
if a > 0 && (a - borrow) >= b {
|
||||
let res = a - b - borrow;
|
||||
|
||||
@ -362,6 +359,18 @@ mod tests {
|
||||
assert_eq!(int.inner[0], 45usize)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_trim_zeros() {
|
||||
let mut lotsoftrailing = BigInt {
|
||||
inner: vec![1, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
sign: Positive
|
||||
};
|
||||
|
||||
lotsoftrailing.trim_zeros();
|
||||
|
||||
assert_eq!(BigInt::from(1), lotsoftrailing);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_add() {
|
||||
// MAX is 2^Bitsize - 1,
|
||||
@ -414,6 +423,17 @@ mod tests {
|
||||
diff.inner[0],
|
||||
core::usize::MAX - 1
|
||||
);
|
||||
|
||||
let a = BigInt {
|
||||
inner: vec![1,0,1],
|
||||
sign: Positive
|
||||
};
|
||||
let b = BigInt::from(2);
|
||||
let diff = a - b;
|
||||
assert_eq!(
|
||||
diff.inner,
|
||||
vec![core::usize::MAX, core::usize::MAX]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user