FLINT3.7.0-dev

nfloat_hypot

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

Sets res to x2+y2\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∣≥∣y∣|x| \ge |y| and dd the difference of the exponents, the result is ∣x∣(1+δ)|x|(1 + \delta) with 0<δ<2−p−30 < \delta < 2^{-p-3} (pp the precision) when dd exceeds about half the precision. Otherwise x2+y2=S⋅22ex^2 + y^2 = S \cdot 2^{2e} for an integer SS of at most 3n+23n + 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, SS 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 SS do not change the floor of the square root. At two words, SS 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/83/8 of the precision), the exact squares are replaced by high squarings (flint_mpn_sqrhigh), whose sum is a lower bound within about 4n4n 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#

Cite this page

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-11-02).