nfloat_inv, nfloat_div, nfloat_div_ui, nfloat_div_si
#include <flint/nfloat.h>int nfloat_inv(nfloat_ptr res, nfloat_srcptr x, gr_ctx_t ctx)sourceint nfloat_div(nfloat_ptr res, nfloat_srcptr x, nfloat_srcptr y, gr_ctx_t ctx)sourceint nfloat_div_ui(nfloat_ptr res, nfloat_srcptr x, ulong y, gr_ctx_t ctx)sourceint nfloat_div_si(nfloat_ptr res, nfloat_srcptr x, slong y, gr_ctx_t ctx)sourceInverse and quotients. Without directed rounding, the result is the quotient truncated toward zero or, for divisors of three or more nonzero words, possibly one ulp larger in magnitude (an error of less than 1 ulp); div_ui and div_si are always truncated. With directed rounding, the result is the correctly rounded floor or ceiling of the exact quotient. Division by zero gives NaN, so it returns GR_UNABLE unless NaN is allowed.
For one and two words, the mantissas are divided by an inlined 2/1 division or two 3/2 divisions, with the dividend shifted right by one bit beforehand when it is larger than the divisor so that the quotient comes out normalised; the remainder gives the exact rounding information. These use hardware division where it is fast (FLINT_PREINVERT_LIMB_USE_NATIVE) and a precomputed inverse otherwise [GraMol2010]. Divisors with a single nonzero word (such as small integers) use a chain of 2/1 divisions, O(n). Otherwise a schoolbook approximate division (_flint_mpn_divapprox_basecase_preinv1) computes the quotient or the quotient plus one at the target precision. With directed rounding, one guard word is computed and the truncation is certified unless the guard word is 0 or 1, in which case (for example for exact quotients) the exact quotient and remainder are computed.
Guides#
References#
- [GraMol2010] N. Möller and T. Granlund, "Improved division by invariant integers", IEEE Transactions on Computers 60 (2011), 165–175, https://gmplib.org/~tege/division-paper.pdf
The FLINT team, “nfloat_inv, nfloat_div, nfloat_div_ui, nfloat_div_si (nfloat.h),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/nfloat/nfloat_inv.html (generated 2026-10-20).
@misc{flint-doc-nfloat-nfloat-inv,
author = {{The FLINT team}},
title = {{nfloat\_inv, nfloat\_div, nfloat\_div\_ui, nfloat\_div\_si (nfloat.h)}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/nfloat/nfloat_inv.html},
note = {Generated 2026-10-20}
}