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());
|
||||
}
|
||||
|
||||
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() {
|
||||
auto const it = std::find_if(digits_.rbegin(), digits_.rend(),
|
||||
[](auto v) { return v != 0; });
|
||||
|
|
|
@ -10,7 +10,17 @@ class BigNum {
|
|||
public:
|
||||
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:
|
||||
bool equal(BigNum const& rhs) const;
|
||||
|
||||
void canonicalize();
|
||||
bool is_canonicalized() const;
|
||||
|
||||
|
|
Loading…
Reference in a new issue