FLINT3.7.0-dev

nfloat_sqrt, nfloat_rsqrt

Synopsis#include <flint/nfloat.h>
int nfloat_sqrt(nfloat_ptr res, nfloat_srcptr x, gr_ctx_t ctx)source
int nfloat_rsqrt(nfloat_ptr res, nfloat_srcptr x, gr_ctx_t ctx)source

Square root and reciprocal square root. The square root is correctly rounded in every mode (truncated toward zero by default); the reciprocal square root has an error of less than 1+2−371 + 2^{-37} ulp by default and is correctly rounded with directed rounding. Negative arguments give NaN.

On the root kernels of Limb-array kernels (_arf_mpn_sqrt_approx and _arf_mpn_rsqrt_approx without directed rounding, _arf_mpn_sqrt and _arf_mpn_rsqrt with it). The square root is the truncated integer square root of the mantissa padded to 2n2n words, with an exactness flag (flint_mpn_sqrthigh_exact, see Floating-point quotients and roots). At one word on 64-bit machines it is computed in registers: a double-precision root (within 2122^{12} of the exact root), one correction from the exact residual evaluated in double precision, and a final exact residual, which gives the floor and the exactness flag. At two words the root is first approximated at three words from the two-word reciprocal square root below and one Newton step with the exact residual, which certifies the truncation unless the guard word is within 3 units of 0 or 2642^{64}.

The reciprocal square root refines a double-precision approximation by one Newton step at 128 bits (one word), or a two-word starting value by one Newton step with the residual evaluated exactly from the six-word product of the mantissa and the square of the starting value (two words). For n≥3n \ge 3 words, the shared flint_mpn_rsqrthigh yields the result with one guard word, within FLINT_MPN_RSQRTHIGH_GUARD_ERR_BOUND units of the guard word. With directed rounding the truncation is certified from these error bounds, and in the rare uncertain cases the exact result ⌊⌊z⌋⌋\lfloor \sqrt{\lfloor z \rfloor} \rfloor is computed (flint_mpn_rsqrthigh_exact) for z=23nw/(4a)z = 2^{3nw}/(4a) or 23nw/(2a)2^{3nw}/(2a), in terms of the nn-word mantissa aa and the word size ww.

Guides#

Cite this page

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