test if an unsigned long fits in a limb.
marc.glisse at inria.fr
Tue Mar 6 20:45:28 CET 2012
On Tue, 6 Mar 2012, bodrato at mail.dm.unipi.it wrote:
> The condition limb != unsigned long is, I fear, poorly tested.
Almost exactly one year after:
> All the code I've found about it, assumes that an UI fits in one or two
> limbs, but the tests are different.
> mpz/iset_ui.c, line 30, reads:
> #if BITS_PER_ULONG > GMP_NUMB_BITS /* avoid warnings about shift amount */
> mpz/iset_si.c, line 39:
> #if GMP_NAIL_BITS != 0
> gmpxx.h, line 61:
> #if GMP_NAIL_BITS != 0 && ! defined _LONG_LONG_LIMB
> gmp-h.in, line 1730:
> #if GMP_NAIL_BITS == 0 || defined (_LONG_LONG_LIMB)
> The first one is the one I prefer.
If you want to use it in gmp.h or gmpxx.h that don't have BITS_PER_ULONG,
would you replace it with a comparison between ULONG_MAX (from limits.h)
Note that mpir is replacing signed/unsigned long by two typedefs that can
be defined as (unsigned) long long on _LONG_LONG_LIMB platforms. That
works around the problem too...
More information about the gmp-devel