abacus: bignum: factorize lexicographical compare

I want to make use of it for substraction.
This commit is contained in:
Bruno BELANYI 2021-08-20 18:44:30 +02:00
parent 6f7e1102db
commit d083ede78c

View file

@ -9,6 +9,17 @@
namespace abacus::bignum { namespace abacus::bignum {
using digits_type = std::vector<std::uint8_t>;
namespace {
bool do_less_than(digits_type const& lhs, digits_type const& rhs) {
return std::lexicographical_compare(lhs.rbegin(), lhs.rend(), rhs.rbegin(),
rhs.rend());
}
} // namespace
BigNum::BigNum(std::int64_t number) { BigNum::BigNum(std::int64_t number) {
if (number == 0) { if (number == 0) {
return; return;
@ -68,9 +79,7 @@ bool BigNum::less_than(BigNum const& rhs) const {
return sign_ < rhs.sign_; return sign_ < rhs.sign_;
} }
return std::lexicographical_compare(digits_.rbegin(), digits_.rend(), return do_less_than(digits_, rhs.digits_);
rhs.digits_.rbegin(),
rhs.digits_.rend());
} }
void BigNum::canonicalize() { void BigNum::canonicalize() {