nfloat_hypot
#include <flint/nfloat.h>int nfloat_hypot(nfloat_ptr res, nfloat_srcptr x, nfloat_srcptr y, gr_ctx_t ctx)sourceSets res to \sqrt{x^2 + y^2}, correctly rounded in every mode (truncated by default), without intermediate overflow or underflow. This also implements nfloat_complex_abs.
With |x| \ge |y| and d the difference of the exponents, the result is |x|(1 + \delta) with 0 < \delta < 2^{-p-3} (p the precision) when d exceeds about half the precision. Otherwise x^2 + y^2 = S \cdot 2^{2e} for an integer S of at most 3n + 2 words (the squares of the mantissas, aligned exactly), whose truncated square root with an inexactness flag gives the result. At one word on 64-bit machines, S is formed in registers and the truncated root is computed from the integer square root of its top two words, since the discarded low bits of S do not change the floor of the square root. At two words, S is formed in registers (the smaller square truncated to the four words of the larger) and its root is approximated with a guard word, which certifies the truncation in all but rare cases. From 12 words (or from 5 words when the exponents differ by at least 3/8 of the precision), the exact squares are replaced by high squarings (flint_mpn_sqrhigh), whose sum is a lower bound within about 4n units of its last word, and the square root with a guard word certifies the truncation likewise, with the exact computation as the fallback.
Guides#
The FLINT team, “nfloat_hypot (nfloat.h),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/nfloat/nfloat_hypot.html (generated 2026-10-20).
@misc{flint-doc-nfloat-nfloat-hypot,
author = {{The FLINT team}},
title = {{nfloat\_hypot (nfloat.h)}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/nfloat/nfloat_hypot.html},
note = {Generated 2026-10-20}
}