From: David Gow Date: Sun, 6 Jul 2014 14:23:57 +0000 (+0800) Subject: digit_t is now unsigned, asm division for 1 digit X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=f1fab7ee4ee08ca10019450beda303ab71a12ee8;p=ipdf%2Fcode.git digit_t is now unsigned, asm division for 1 digit We now do the "two's complement" in SubBasic by hand. It is maybe even correct. --- diff --git a/src/arbint.cpp b/src/arbint.cpp index ac39942..696dcd0 100644 --- a/src/arbint.cpp +++ b/src/arbint.cpp @@ -119,6 +119,13 @@ void Arbint::Division(const Arbint & div, Arbint & result, Arbint & remainder) c result = *this; return; } + else if (div.m_digits.size() == 1) + { + result.m_digits.resize(m_digits.size(), 0L); + remainder = Arbint(div_digits((digit_t*)&m_digits[0], div.m_digits[0], m_digits.size(), result.m_digits.data())); + result.m_sign = !(m_sign == div.m_sign); + return; + } for (int i = 8*sizeof(digit_t)*m_digits.size(); i >= 0; --i) { remainder <<= 1; @@ -196,7 +203,7 @@ Arbint & Arbint::SubBasic(const Arbint & sub) { m_sign = !m_sign; for (unsigned i = 0; i < m_digits.size(); ++i) - m_digits[i] = -m_digits[i]; + m_digits[i] = (~m_digits[i]) + 1; } return *this; }