summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--number.cpp14
1 files changed, 3 insertions, 11 deletions
diff --git a/number.cpp b/number.cpp
index ae4b167..d16f37f 100644
--- a/number.cpp
+++ b/number.cpp
@@ -67,11 +67,6 @@ number::to_uint32() const
number
number::operator+(const number &n) const
{
- /* We make sure our object is greater than or equal to n. */
- if (*this < n) {
- return n.operator+(*this);
- }
-
number result;
auto it = _operands.cbegin();
@@ -79,9 +74,9 @@ number::operator+(const number &n) const
bool carry = false;
- while (it != _operands.cend()) {
- const auto n1 = *it;
- const auto n2 = *it_n;
+ while (it != _operands.cend() || it_n != n._operands.cend()) {
+ const auto n1 = (it != _operands.cend()) ? *it++ : 0;
+ const auto n2 = (it_n != n._operands.cend()) ? *it_n++ : 0;
result._operands.push_back(n1 + n2 + (carry ? 1 : 0));
@@ -90,9 +85,6 @@ number::operator+(const number &n) const
} else {
carry = ((UINT32_MAX - n1 - (carry ? 1 : 0)) < n2);
}
-
- ++it;
- ++it_n;
}
if (carry) {