New function mpz_init_setbit
marco.bodrato at tutanota.com
marco.bodrato at tutanota.com
Thu Jun 25 14:43:25 CEST 2026
Ciao!
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;
}
And in mini-gmp:
void
mpz_init_setbit (mpz_t r, mp_bitcnt_t b)
{
mpz_init (r);
/* mpz_setbit (r, b); */
mpz_abs_add_bit (r, b);
}
Ĝis,
m--
DC: https://vado.li/dc-bodrato
More information about the gmp-devel
mailing list