FLINT3.7.0-dev
Guide · nfloat.h

Rounding in nfloat

The rounding mode of an nfloat context is set with the flags NFLOAT_RND_FLOOR and NFLOAT_RND_CEIL of nfloat_ctx_init. Without either flag (the default mode), results are rounded in an unspecified direction for efficiency, usually toward zero. With one of them, the operations listed below as correctly rounded return the floor or the ceiling of the exact result, and the others listed as bounded return a lower or upper bound, which makes it possible to compute rigorous enclosures with pairs of contexts. Directed rounding is experimental and may not work correctly together with NFLOAT_ALLOW_UNDERFLOW. The matrix multiplication of nfloat_mat_mul falls back to the classical algorithm in contexts with directed rounding.

Exact operations#

These return the exact value in every mode: nfloat_set, nfloat_neg, nfloat_abs, nfloat_mul_2exp_si (barring overflow and underflow), nfloat_floor, nfloat_ceil, nfloat_nint, nfloat_trunc, nfloat_sgn, and the conversions out of nfloat that are exact (nfloat_get_arf, nfloat_get_fmpz).

Correctly rounded in every mode#

In the default mode the result is the exact value truncated toward zero; with NFLOAT_RND_FLOOR or NFLOAT_RND_CEIL it is the correctly rounded floor or ceiling:

Correctly rounded with directed rounding#

With NFLOAT_RND_FLOOR or NFLOAT_RND_CEIL these give the correctly rounded floor or ceiling; in the default mode the error is as noted:

Valid bounds with directed rounding#

With NFLOAT_RND_FLOOR or NFLOAT_RND_CEIL these return a lower or an upper bound for the exact value, but not in general the correctly rounded one:

Not respecting the rounding mode#

These ignore the rounding flags, and the direction of the error is arbitrary:

Results that are not correctly rounded are not guaranteed to be identical on 64-bit and 32-bit machines.

Cite this page

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