FLINT3.7.0-dev

flint_mpn_pow

Synopsis#include <flint/mpn_extras.h>
mp_size_t flint_mpn_pow(mp_ptr res, mp_srcptr x, mp_size_t xn, ulong e)source

Sets \mathit{res} to x^e by left-to-right binary exponentiation and returns the number of limbs of the result. res must have room for flint_mpn_pow_bound_limbs(x, xn, e) limbs and must not overlap x. Requires \mathit{xn} \ge 1 and x_{xn-1} \ne 0; e = 0 gives 1.

Low zero limbs of x are stripped and restored as an offset in the output; trailing zero bits are shifted out only when the base is short (at most 8 limbs) and restored with one shift of the result. While the power fits in one or two limbs, fixed-size arithmetic is used. Afterwards the running power alternates between res and a scratch buffer without copying: the parity of the remaining out-of-place operations is chosen so that the final product lands in res, and multiplications by a single-limb base are done in place with mpn_mul_1.

Cite this page

The FLINT team, “flint_mpn_pow (mpn_extras.h),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/mpn_extras/flint_mpn_pow.html (generated 2026-10-20).