Skip to main content
added 565 characters in body
Source Link
JDługosz
  • 11.7k
  • 19
  • 40
    if(a.negative!=b.negative){
        return false;
    }
    return std::equal(a.container.begin(),a.container.end(),b.container.begin(),b.container.end());
}

For the last line, doesn't vector's operator== do what you need?

So you end up just checking if all the data members are equal. So use the C++20 capability to autogenerate it.

But you mentioned using C++20 in order to have <=> and that includes == when you have strong_ordering. So why do you define this at all?


unsigned int digits=container.size();

you mean size_t. Or why not use auto? And shouldn't it be const?

int diff=container[k]-b.getDigit(k)-rem;

you're mixing signed and unsigned arithmetic. Or rather, you're doing unsigned subtractions (promoted to unsigned int for the second subtract operation) and then casting that to signed. You'll have trouble if you change the type of the container's element (like making it the largest word you can handle).

Why do you need to call normalize() at the end of the subtract function?

    if(a.negative!=b.negative){
        return false;
    }
    return std::equal(a.container.begin(),a.container.end(),b.container.begin(),b.container.end());
}

For the last line, doesn't vector's operator== do what you need?

So you end up just checking if all the data members are equal. So use the C++20 capability to autogenerate it.

But you mentioned using C++20 in order to have <=> and that includes == when you have strong_ordering. So why do you define this at all?

    if(a.negative!=b.negative){
        return false;
    }
    return std::equal(a.container.begin(),a.container.end(),b.container.begin(),b.container.end());
}

For the last line, doesn't vector's operator== do what you need?

So you end up just checking if all the data members are equal. So use the C++20 capability to autogenerate it.

But you mentioned using C++20 in order to have <=> and that includes == when you have strong_ordering. So why do you define this at all?


unsigned int digits=container.size();

you mean size_t. Or why not use auto? And shouldn't it be const?

int diff=container[k]-b.getDigit(k)-rem;

you're mixing signed and unsigned arithmetic. Or rather, you're doing unsigned subtractions (promoted to unsigned int for the second subtract operation) and then casting that to signed. You'll have trouble if you change the type of the container's element (like making it the largest word you can handle).

Why do you need to call normalize() at the end of the subtract function?

Source Link
JDługosz
  • 11.7k
  • 19
  • 40

    if(a.negative!=b.negative){
        return false;
    }
    return std::equal(a.container.begin(),a.container.end(),b.container.begin(),b.container.end());
}

For the last line, doesn't vector's operator== do what you need?

So you end up just checking if all the data members are equal. So use the C++20 capability to autogenerate it.

But you mentioned using C++20 in order to have <=> and that includes == when you have strong_ordering. So why do you define this at all?