Skip to content

Commit

Permalink
Small subtraction fix (#9)
Browse files Browse the repository at this point in the history
It had been wrong subtraction result for large numbers and during
zeroing of upper num they aren't deleted that led to incorrect
comparison
  • Loading branch information
Quill88 authored and kasparsklavins committed Jan 28, 2017
1 parent 1b840c7 commit ab6c858
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/bigint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Bigint &Bigint::operator-=(Bigint const &b)
++it2;
}
if (dif < 0) {
*(it1 - 1) = (dif * (-1)) % base;
*(it1 - 1) = dif + base;
dif = -1;
} else {
*(it1 - 1) = dif % base;
Expand All @@ -169,6 +169,16 @@ Bigint &Bigint::operator-=(Bigint const &b)
}
if (dif < 0) positive = false;

if (number.size() > 1)
{
do
{
it1 = number.end() - 1;
if (*it1 == 0) number.pop_back();
else break;
} while (number.size() > 1);
}

return *this;
}

Expand Down

0 comments on commit ab6c858

Please sign in to comment.