Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some BigInt relational operators are not optimal #76

Open
dynarithmic opened this issue May 16, 2024 · 0 comments
Open

Some BigInt relational operators are not optimal #76

dynarithmic opened this issue May 16, 2024 · 0 comments

Comments

@dynarithmic
Copy link

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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant