FLINT3.7.0-dev

mpn_mod_mul, mpn_mod_sqr

Synopsis#include <flint/mpn_mod.h>
int mpn_mod_mul(nn_ptr res, nn_srcptr x, nn_srcptr y, gr_ctx_t ctx)source
int mpn_mod_sqr(nn_ptr res, nn_srcptr x, gr_ctx_t ctx)source

Set res to xy and x^2 modulo n.

The product (x 2^{\nu}) y of 2\ell limbs is reduced modulo n 2^{\nu} with the precomputed inverse of the context (a quotient estimate from one high product and one low product, followed by at most a few subtractions) and shifted back; see Modular multiplication with a multiword modulus. Two-limb moduli use the inline code of flint_mpn_mulmod_preinvn_2. When x and y are the same pointer, the product is computed by squaring. This is the algorithm of flint_mpn_mulmod_preinvn, with the shift applied to an input instead of the output.

Guides#

Cite this page

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