FLINT3.7.0-dev

flint_mpn_divexact

Synopsis#include <flint/mpn_extras.h>
void flint_mpn_divexact(mp_ptr q, mp_srcptr a, mp_size_t an, mp_srcptr b, mp_size_t bn)source

Exact division: sets (q,an−bn+1)(q, \mathit{an} - \mathit{bn} + 1) to a/ba/b, assuming that bb divides aa (otherwise the result is meaningless).

Single-limb divisors are handled by mpn_divexact_1. Otherwise the division is done 2-adically: writing b=2vBkb′b = 2^v B^k b' with b′b' odd, the quotient is (a/(2vBk)) b′−1 mod Bm(a / (2^v B^k))\, b'^{-1} \bmod B^m, where mm is the number of quotient limbs (an−bn+1\mathit{an} - \mathit{bn} + 1, or one less when the top limb of aa is below that of bb). With d=min⁡(bn,m)d = \min(\mathit{bn}, m) significant divisor limbs, d≤7d \le 7 uses register-resident code specialised for each dd, with the shift done on the fly and the limb inverse b′−1 mod Bb'^{-1} \bmod B computed inline. Larger dd use ports of GMP's schoolbook and divide and conquer Hensel division (mpn_sbpi1_bdiv_q, and mpn_dcpi1_bdiv_q from FLINT_MPN_DC_BDIV_Q_CUTOFF limbs) with FLINT's multiplication, and the Newton iteration flint_mpn_bdiv_q from d≥d \ge FLINT_MPN_DIVEXACT_NEWTON_CUTOFF, or already from bn≥\mathit{bn} \ge FLINT_MPN_DIVEXACT_UNBALANCED_CUTOFF when m≥4bnm \ge 4 \mathit{bn}.

Cite this page

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