fmpz_extras.h – extra methods for FLINT integers¶
This module implements a few utility methods for the FLINT multiprecision integer type (fmpz_t). It is mainly intended for internal use.
Convenience methods¶

void
fmpz_sub_si
(fmpz_t z, const fmpz_t x, slong y)¶ Sets z to the sum (respectively difference) of x and y.

void
fmpz_adiv_q_2exp
(fmpz_t z, const fmpz_t x, flint_bitcnt_t exp)¶ Sets z to \(x / 2^{exp}\), rounded away from zero.
Inlined arithmetic¶
The fmpz_t bignum type uses an immediate representation for small integers, specifically when the absolute value is at most \(2^{62}1\) (on 64bit machines) or \(2^{30}1\) (on 32bit machines). The following methods completely inline the case where all operands (and possibly some intermediate values in the calculation) are known to be small. This is faster in code where all values almost certainly will be much smaller than a full word. In particular, these methods are used within Arb for manipulating exponents of floatingpoint numbers. Inlining slows down the general case, and increases code size, so these methods should not be used gratuitously.

void
fmpz_add2_fmpz_si_inline
(fmpz_t z, const fmpz_t x, const fmpz_t y, slong c)¶ Sets z to the sum of x, y, and c.
Lowlevel conversions¶

void
fmpz_set_mpn_large
(fmpz_t z, mp_srcptr src, mp_size_t n, int negative)¶ Sets z to the integer represented by the n limbs in the array src, or minus this value if negative is 1. Requires \(n \ge 2\) and that the top limb of src is nonzero. Note that fmpz_set_ui, fmpz_neg_ui can be used for singlelimb integers.

FMPZ_GET_MPN_READONLY
(zsign, zn, zptr, ztmp, zv)¶ Given an fmpz_t zv, this macro sets zptr to a pointer to the limbs of zv, zn to the number of limbs, and zsign to a sign bit (0 if nonnegative, 1 if negative). The variable ztmp must be a single mp_limb_t, which is used as a buffer. If zv is a small value, zv itself contains no limb array that zptr could point to, so the single limb is copied to ztmp and zptr is set to point to ztmp. The case where zv is zero is not handled specially, and zn is set to 1.

void
fmpz_lshift_mpn
(fmpz_t z, mp_srcptr src, mp_size_t n, int negative, flint_bitcnt_t shift)¶ Sets z to the integer represented by the n limbs in the array src, or minus this value if negative is 1, shifted left by shift bits. Requires \(n \ge 1\) and that the top limb of src is nonzero.