Ver código fonte

Fixing bug where we pushed the numbers forward, causing them to be 1,000,000,000^diff times as large as appropriate.

Sam Jaffe 7 anos atrás
pai
commit
5e5345b1f7
2 arquivos alterados com 3 adições e 3 exclusões
  1. 1 1
      src/bigdecimal.cpp
  2. 2 2
      test/bigdecimal_test.cpp

+ 1 - 1
src/bigdecimal.cpp

@@ -206,7 +206,7 @@ bigdecimal & math::operator/=(bigdecimal & rhs, bigdecimal const & lhs) {
       rhs.data = detail::divide(rhs.data, lhs.data);
       auto diff = add_scale(new_scale) - rhs.steps_ - lhs.steps_;
       if (diff > 0) {
-        rhs.data.insert(rhs.data.begin(), size_t(diff), 0);
+        rhs.data.erase(rhs.data.begin(), rhs.data.begin() + diff);
       }
       if (rhs.data.size() <= mul_scale(new_scale)) {
         rhs.data.push_back(0);

+ 2 - 2
test/bigdecimal_test.cpp

@@ -130,7 +130,7 @@ INSTANTIATE_TEST_CASE_P(BigDecimal, DivisionScaleTest,
                                         ArithTuple{{"1.1"}, {"1.1"}, "1"},
 //                                        ArithTuple{{"0.01"}, {100, -2}, "1"}, // Infinite loop because of leading 0?
                                         ArithTuple{{1, 5}, {1,  5}, "1"},
-//                                        ArithTuple{{1, 5}, {1000000000, -9}, "0.00000000100000"}, // 1,000,000,000.00000000000000 As if multiplied, but with div scale
-//                                        ArithTuple{{100, -2}, {1000000000, -9}, "0.0000001"}, // 100,000,000,000.0000000 As if multiplied, but with div scale
+                                        ArithTuple{{1, 5}, {1000000000, -9}, "0.00000000100000"},
+                                        ArithTuple{{100, -2}, {1000000000, -9}, "0.0000001"},
                                         ArithTuple{{10000, -4}, {100000, -5}, "0.1"}));
 #pragma clang diagnostic pop