abacus: bignum: add equality comparisons
This commit is contained in:
parent
2cff603a48
commit
17bd51d197
|
@ -27,6 +27,17 @@ BigNum::BigNum(std::int64_t number) {
|
||||||
assert(is_canonicalized());
|
assert(is_canonicalized());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BigNum::equal(BigNum const& rhs) const {
|
||||||
|
assert(is_canonicalized());
|
||||||
|
assert(rhs.is_canonicalized());
|
||||||
|
|
||||||
|
if (sign_ != rhs.sign_) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return digits_ == rhs.digits_;
|
||||||
|
}
|
||||||
|
|
||||||
void BigNum::canonicalize() {
|
void BigNum::canonicalize() {
|
||||||
auto const it = std::find_if(digits_.rbegin(), digits_.rend(),
|
auto const it = std::find_if(digits_.rbegin(), digits_.rend(),
|
||||||
[](auto v) { return v != 0; });
|
[](auto v) { return v != 0; });
|
||||||
|
|
|
@ -10,7 +10,17 @@ class BigNum {
|
||||||
public:
|
public:
|
||||||
explicit BigNum(std::int64_t number);
|
explicit BigNum(std::int64_t number);
|
||||||
|
|
||||||
|
friend bool operator==(BigNum const& lhs, BigNum const& rhs) {
|
||||||
|
return lhs.equal(rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
friend bool operator!=(BigNum const& lhs, BigNum const& rhs) {
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool equal(BigNum const& rhs) const;
|
||||||
|
|
||||||
void canonicalize();
|
void canonicalize();
|
||||||
bool is_canonicalized() const;
|
bool is_canonicalized() const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue