From f1fab7ee4ee08ca10019450beda303ab71a12ee8 Mon Sep 17 00:00:00 2001 From: David Gow Date: Sun, 6 Jul 2014 22:23:57 +0800 Subject: [PATCH] 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. --- src/arbint.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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; } -- 2.20.1