py/mpz: In mpn_sub, use existing function to remove trailing zeros.

This commit is contained in:
Damien George 2017-04-25 12:22:04 +10:00
parent 810133d97d
commit f85fd79c6c

View File

@ -49,6 +49,12 @@
Definition of normalise: ? 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 /* compares i with j
returns sign(i - j) returns sign(i - j)
assumes i, j are normalised 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; borrow >>= DIG_SIZE;
} }
for (--idig; idig >= oidig && *idig == 0; --idig) { return mpn_remove_trailing_zeros(oidig, 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;
} }
#if MICROPY_OPT_MPZ_BITWISE #if MICROPY_OPT_MPZ_BITWISE