BigInt icon indicating copy to clipboard operation
BigInt copied to clipboard

Some BigInt relational operators are not optimal

Open dynarithmic opened this issue 1 year ago • 0 comments

The BigInt relational operators, for example BigInt::operator> are not optimal.

Currently, the code is:

bool BigInt::operator>(const BigInt& num) const {
    return !((*this < num) or (*this == num));
}

This potentially makes two calls, one to operator< and another to operator ==. Only one call needs to be made:

bool BigInt::operator>(const BigInt& num) const {
    return *this < num;
}

The same issue with <=, where it takes just < to give the right results. Here is the corrected code:


bool BigInt::operator<=(const BigInt& num) const {
    return !(num < *this);
}

dynarithmic avatar May 16 '24 20:05 dynarithmic