FLINT3.7.0-dev

fmpz_mod_ctx_init, fmpz_mod_ctx_init_ui

Synopsis#include <flint/fmpz_mod.h>
void fmpz_mod_ctx_init(fmpz_mod_ctx_t ctx, const fmpz_t n)source
void fmpz_mod_ctx_init_ui(fmpz_mod_ctx_t ctx, ulong n)source

Initialises ctx for arithmetic modulo n. Throws an exception if n \le 0.

The context records which code to use for n:

Modulusfmpz_mod_add, _sub, _mul use
n < 2^{\mathtt{FLINT\_BITS}}nmod arithmetic (_fmpz_mod_add1, ...)
n = 2^{\mathtt{FLINT\_BITS}}wrapping word arithmetic (_fmpz_mod_add2s, ...)
2^{\mathtt{FLINT\_BITS}} < n < 2^{2\mathtt{FLINT\_BITS}}two-limb arithmetic with a Barrett inverse (_fmpz_mod_add2, ...)
more than two limbsfmpz arithmetic (_fmpz_mod_addN, ...)

For moduli of more than 20 limbs it also precomputes an inverse for fmpz_fdiv_r_preinvn, which multiplications then use instead of fmpz_mod. See Two-limb Barrett reduction in fmpz_mod for the two-limb reduction.

Guides#

Cite this page

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