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)sourcevoid fmpz_mod_ctx_init_ui(fmpz_mod_ctx_t ctx, ulong n)sourceInitialises ctx for arithmetic modulo n. Throws an exception if n \le 0.
The context records which code to use for n:
| Modulus | fmpz_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 limbs | fmpz 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#
- Using fmpz_mod
- Prime and composite moduli (
fmpz_mod_mat) - Getting started with fmpz_mod_poly (
fmpz_mod_poly) - Getting started with finite fields (
fq_default)
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).
@misc{flint-doc-fmpz-mod-fmpz-mod-ctx-init,
author = {{The FLINT team}},
title = {{fmpz\_mod\_ctx\_init, fmpz\_mod\_ctx\_init\_ui (fmpz\_mod.h)}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/fmpz_mod/fmpz_mod_ctx_init.html},
note = {Generated 2026-10-20}
}