void Arbint::Division(const Arbint & div, Arbint & result, Arbint & remainder) const
{
- //TODO: Optimise?
+ if (div == Arbint(1L))
+ {
+ result = *this;
+ remainder = 0L;
+ return;
+ }
+ if (div == *this)
+ {
+ result = 1L;
+ remainder = 0L;
+ return;
+ }
+
+
+ result = 0L;
remainder = *this;
- result = 0L;
- while ((remainder -= div) > 0L)
+ Arbint next_rem(remainder);
+ while ((next_rem -= div) >= Arbint(0L))
{
- //Debug("Remainder %c%s", remainder.SignChar(), remainder.DigitStr().c_str());
- //Debug("Result %c%s + 1", result.SignChar(), result.DigitStr().c_str());
- result += 1;
+ //Debug("%li - %li = %li", digit_t(remainder), digit_t(div), digit_t(next_rem));
+ //Debug("Sign is %d", next_rem.m_sign);
+ remainder = next_rem;
+ result += 1L;
}
- remainder += div;
+
+
}
Arbint & Arbint::operator+=(const Arbint & add)
bool Arbint::operator==(const Arbint & equ) const
{
- if (m_sign != equ.m_sign) return false;
+ if (m_sign != equ.m_sign)
+ return false;
unsigned min_size = m_digits.size();
const Arbint * larger = &equ;
if (m_digits.size() > equ.m_digits.size())