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^{-37} ulp by default and is correctly rounded with directed rounding. Negative arguments give NaN.

The square root is the truncated integer square root of the mantissa padded to 2n words, with an exactness flag (flint_mpn_sqrtrem). At one word on 64-bit machines it is computed in registers: a double-precision root (within 2^{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 2^{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 \ge 3 words, a fixed-point Newton iteration with an added third-order term yields the result with one guard word and an error of about one unit in the guard word. With directed rounding the truncation is certified from these error bounds, and in the rare uncertain cases the exact result \lfloor \sqrt{\lfloor z \rfloor} \rfloor is computed for z = 2^{3nw}/(4a) or 2^{3nw}/(2a), in terms of the n-word mantissa a and the word size w.

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-10-20).