diff --git a/src/bigint.rs b/src/bigint.rs index c47bf88..1e6cf67 100644 --- a/src/bigint.rs +++ b/src/bigint.rs @@ -175,15 +175,9 @@ 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 && (a - borrow) >= b { + if a >= borrow && (a - borrow) >= b { let res = a - b - borrow; - // Don't add an extra zero if you borrowed everything - // from the most significant digit - if res == 0 && digits > 0 && i == digits -1 { - return out; - } - out.inner.push(res); borrow = 0; } else { @@ -462,9 +456,9 @@ mod tests { let a = BigInt::new(); let b = BigInt::new(); - // let c = a.clone() - b.clone(); - // assert_eq!(a.clone(), b.clone()); - // assert_eq!(c, a.clone()); + let c = a.clone() - b.clone(); + assert_eq!(a.clone(), b.clone()); + assert_eq!(c, a.clone()); let c = a.clone() + b.clone(); assert_eq!(a.clone(), b.clone());