abacus: bignum: fix carry bug in addition

This commit is contained in:
Bruno BELANYI 2021-08-21 01:23:23 +02:00
parent c23500607f
commit 7cd0664e60
2 changed files with 13 additions and 0 deletions

View file

@ -52,6 +52,10 @@ digits_type do_addition(digits_type const& lhs, digits_type const& rhs) {
++it; ++it;
} }
if (carry != 0) {
res.push_back(carry);
}
return res; return res;
} }

View file

@ -115,6 +115,15 @@ TEST(BigNum, addition_flips_sign) {
EXPECT_EQ(two + minus_one, one); EXPECT_EQ(two + minus_one, one);
} }
TEST(BigNum, addition_carry) {
auto const one = BigNum(1);
auto const nine = BigNum(9);
auto const ten = BigNum(10);
EXPECT_EQ(one + nine, ten);
EXPECT_EQ(nine + one, ten);
}
TEST(BigNum, substraction_positive) { TEST(BigNum, substraction_positive) {
auto const zero = BigNum(0); auto const zero = BigNum(0);
auto const one = BigNum(1); auto const one = BigNum(1);