abacus: bignum: fix order comparisons

This is a pretty big oversight...
This commit is contained in:
Bruno BELANYI 2021-08-21 12:48:37 +02:00
parent 5bc3963317
commit 3397bf4310
2 changed files with 12 additions and 0 deletions

View file

@ -16,6 +16,10 @@ namespace {
auto static constexpr BASE = 10; auto static constexpr BASE = 10;
bool do_less_than(digits_type const& lhs, digits_type const& rhs) { bool do_less_than(digits_type const& lhs, digits_type const& rhs) {
if (lhs.size() != rhs.size()) {
return lhs.size() < rhs.size();
}
return std::lexicographical_compare(lhs.rbegin(), lhs.rend(), rhs.rbegin(), return std::lexicographical_compare(lhs.rbegin(), lhs.rend(), rhs.rbegin(),
rhs.rend()); rhs.rend());
} }

View file

@ -60,6 +60,14 @@ TEST(BigNum, comparisons) {
EXPECT_GE(one, one); EXPECT_GE(one, one);
} }
TEST(BigNum, comparisons_digits) {
auto const nine = BigNum(9);
auto const ten = BigNum(10);
EXPECT_LT(nine, ten);
EXPECT_GT(ten, nine);
}
TEST(BigNum, unary) { TEST(BigNum, unary) {
auto const zero = BigNum(0); auto const zero = BigNum(0);
auto const one = BigNum(1); auto const one = BigNum(1);