From f85fd79c6c37cdbd32d9edc37efc985f1f4bc3bb Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 25 Apr 2017 12:22:04 +1000 Subject: [PATCH] py/mpz: In mpn_sub, use existing function to remove trailing zeros. --- py/mpz.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/py/mpz.c b/py/mpz.c index c6832e3898..f5675a2917 100644 --- a/py/mpz.c +++ b/py/mpz.c @@ -49,6 +49,12 @@ Definition of normalise: ? */ +STATIC size_t mpn_remove_trailing_zeros(mpz_dig_t *oidig, mpz_dig_t *idig) { + for (--idig; idig >= oidig && *idig == 0; --idig) { + } + return idig + 1 - oidig; +} + /* compares i with j returns sign(i - j) assumes i, j are normalised @@ -190,16 +196,7 @@ STATIC size_t mpn_sub(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const borrow >>= DIG_SIZE; } - for (--idig; idig >= oidig && *idig == 0; --idig) { - } - - return idig + 1 - oidig; -} - -STATIC size_t mpn_remove_trailing_zeros(mpz_dig_t *oidig, mpz_dig_t *idig) { - for (--idig; idig >= oidig && *idig == 0; --idig) { - } - return idig + 1 - oidig; + return mpn_remove_trailing_zeros(oidig, idig); } #if MICROPY_OPT_MPZ_BITWISE