test if an unsigned long fits in a limb.

Marc Glisse 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:
http://gmplib.org/list-archives/gmp-devel/2011-March/001823.html
:-)

> 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) 
and GMP_NUMB_MAX?

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...

-- 
Marc Glisse


More information about the gmp-devel mailing list