FLINT3.7.0-dev

_arf_mpn_round_guarded

Synopsis#include <flint/arf.h>
int _arf_mpn_round_guarded(nn_ptr res, slong * exp, nn_srcptr a, slong n, ulong g, int e, slong prec, arf_rnd_t rnd, int side)source

Given the nn normalised limbs a and the limb g below them, which together approximate a value to within 2e2^e ulps of g (in either direction for side = 0, strictly above the approximation for side = 1, strictly below it for side = −1-1), rounds the value to prec≤n⋅FLINT_BITS\mathit{prec} \le n \cdot \mathtt{FLINT\_BITS} bits when the guard limb certifies the rounding: writes the ⌈prec/FLINT_BITS⌉\lceil \mathit{prec} / \mathtt{FLINT\_BITS} \rceil limbs to res (which may be a, or lie below it in the same buffer), sets exp to the change of the exponent (−1-1, 0 or 1) and returns 1, the value being inexact. Returns −1-1 when the window does not certify the rounding; the exact value must then be computed.

With the approximation AA within 2e2^e ulps of the exact value PP and k≥FLINT_BITSk \ge \mathtt{FLINT\_BITS} discarded bits, the bits e,…,FLINT_BITS−2e, \ldots, \mathtt{FLINT\_BITS} - 2 of g being neither all zero nor all ones gives 2e≤A mod 2k−1<2k−1−2e2^e \le A \bmod 2^{k-1} < 2^{k-1} - 2^e, so that PP lies strictly between the same rounding boundaries as AA (the truncation point and the half point) and is not exact; the rounding of AA is then the rounding of PP in every mode [AJ2025]. The check fails with probability about 2e+1−FLINT_BITS2^{e + 1 - \mathtt{FLINT\_BITS}}. With the direction of the error known, only the boundary in that direction matters: all zeros will do for a value above the approximation (which then rounds like the approximation with sticky bits), all ones for one below; and a value just below an approximation that is exact at prec bits rounds to it, or to the value below it when rounding toward zero.

References#

Cite this page

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