Browse Source

bigint: use full cmp results for checked_sub

Josh Stone 9 years ago
parent
commit
c9e15aef2d
1 changed files with 4 additions and 3 deletions
  1. 4 3
      src/bigint.rs

+ 4 - 3
src/bigint.rs

@@ -971,10 +971,11 @@ impl CheckedAdd for BigUint {
 impl CheckedSub for BigUint {
     #[inline]
     fn checked_sub(&self, v: &BigUint) -> Option<BigUint> {
-        if *self < *v {
-            return None;
+        match self.cmp(v) {
+            Less => None,
+            Equal => Some(Zero::zero()),
+            Greater => Some(self.sub(v)),
         }
-        return Some(self.sub(v));
     }
 }