From 918e77b678b4e92ec38cb850ea53a1fc8597c4d0 Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Tue, 4 Oct 2022 22:18:22 -0700 Subject: [PATCH] Minor cleanup. --- bigjoyints/big.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/bigjoyints/big.py b/bigjoyints/big.py index 11adab1..2ce65e7 100644 --- a/bigjoyints/big.py +++ b/bigjoyints/big.py @@ -99,34 +99,29 @@ class BigInt: acc = BigInt() for i, digit in enumerate(other.digits): - intermediate_result = self._mul_one_digit(i, digit) - #print(intermediate_result) - acc = acc + intermediate_result + acc = acc + self._mul_one_digit(i, digit) acc.sign = not (self.sign ^ other.sign) return acc def _mul_one_digit(self, power, n): # Some of this should go in a method of OberonInt? - out = [zero] * power + digits = [zero] * power carry = zero for digit in self.digits: - # In the Oberon RISC the high half of multiplication - # is put into the special H register. - H, product = digit * n - c, p = product + carry - out.append(p) - carry = H + high, low = digit * n + c, p = low + carry + digits.append(p) + carry = high if c: z, carry = carry + one assert not z, repr(z) if carry.value: assert carry.value > 0 - out.append(carry) + digits.append(carry) result = BigInt() - result.digits = out + result.digits = digits return result - def add_like_signs(self, other): ''' Add a BigInt of the same sign as self. -- 2.11.0