abacus: bignum: fix carry bug in addition
This commit is contained in:
parent
c23500607f
commit
7cd0664e60
|
@ -52,6 +52,10 @@ digits_type do_addition(digits_type const& lhs, digits_type const& rhs) {
|
|||
++it;
|
||||
}
|
||||
|
||||
if (carry != 0) {
|
||||
res.push_back(carry);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -115,6 +115,15 @@ TEST(BigNum, addition_flips_sign) {
|
|||
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) {
|
||||
auto const zero = BigNum(0);
|
||||
auto const one = BigNum(1);
|
||||
|
|
Loading…
Reference in a new issue