Ver código fonte

Fix pop-back when no overflow occurs in multiplication.

Samuel Jaffe 8 anos atrás
pai
commit
4ab111f25f
2 arquivos alterados com 6 adições e 1 exclusões
  1. 1 1
      src/biginteger.cpp
  2. 5 0
      test/biginteger.t.h

+ 1 - 1
src/biginteger.cpp

@@ -193,7 +193,7 @@ namespace detail {
         rval[i+1] += overflow;
       }
     }
-    if (rval[ubnd] == 0) { rval.pop_back(); }
+    while (rval.back() == 0 && rval.size() > 1) { rval.pop_back(); }
     return rval;
   }
 }

+ 5 - 0
test/biginteger.t.h

@@ -90,4 +90,9 @@ public:
     TS_ASSERT_EQUALS((big*big).to_string(),
                      "999999996000000005999999996000000001");
   }
+  
+  void testMultiplyNoOverflow() {
+    math::biginteger bi{1000};
+    TS_ASSERT_EQUALS((bi*bi).to_string(), "1000000");
+  }
 };