LIMBS_PER_DIGIT_IN_BASE
Zimmermann Paul
Paul.Zimmermann at inria.fr
Mon Dec 16 23:20:44 UTC 2013
Hi,
about the following macro in gmp-impl.h:
/* Compute the number of limbs corresponding to ndigits base-b digits, rounding
up. */
#define LIMBS_PER_DIGIT_IN_BASE(res, ndigits, b) \
do { \
mp_limb_t _ph, _dummy; \
umul_ppmm (_ph, _dummy, mp_bases[b].log2b, (mp_limb_t) (ndigits)); \
res = 8 * _ph / GMP_NUMB_BITS + 2; \
} while (0)
On a 32-bit machine, mp_bases[b].log2b is floor(2^32*log(b)/8/log(2)).
Thus for ndigits > 2^32*log(2)/log(b), we have _ph >= 2^32/8, and the
computation 8 * _ph in res will overflow, unless I'm wrong.
Paul
More information about the gmp-devel
mailing list