New function mpz_init_setbit
Torbjörn Granlund
tg at gmplib.org
Thu Jun 25 16:18:47 CEST 2026
marco.bodrato at tutanota.com writes:
Do you mind if I add a new function?
Here is its implementation:
/* mpz_init_setbit(integer, val) -- Initialize and assign INTEGER with 2^VAL. */
void
mpz_init_setbit (mpz_ptr dest, mp_bitcnt_t bit_idx)
{
mp_ptr dp;
mp_size_t limb_idx = bit_idx / GMP_NUMB_BITS;
mp_limb_t mask = CNST_LIMB(1) << (bit_idx % GMP_NUMB_BITS);
ALLOC (dest) = SIZ (dest) = limb_idx + 1;
PTR (dest) = dp = __GMP_ALLOCATE_FUNC_LIMBS (limb_idx + 1);
MPN_ZERO (dp, limb_idx);
dp[limb_idx] = mask;
}
I suppose that the name should be mpz_set_2exp, for consistency?
--
Torbjörn
Please encrypt, key id 0xC8601622
More information about the gmp-devel
mailing list