Skip to content

Some BigInt relational operators are not optimal #76

@dynarithmic

Description

@dynarithmic

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions