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 · May be fixed by #78
Open

Some BigInt relational operators are not optimal #76

dynarithmic opened this issue May 16, 2024 · 0 comments · May be fixed by #78

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);
}
@itstrueitstrueitsrealitsreal itstrueitstrueitsrealitsreal linked a pull request Jan 28, 2025 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant