FLINT3.7.0-dev

decimal_ctx_set_prec, decimal_ctx_set_rnd, decimal_ctx_set_rnd_im, decimal_ctx_set_rad_prec, decimal_ctx_set_exp_limits, decimal_ctx_set_flags

Synopsis#include <flint/decimal.h>
void decimal_ctx_set_prec(gr_ctx_t ctx, slong prec)source
void decimal_ctx_set_rnd(gr_ctx_t ctx, int rnd)source
void decimal_ctx_set_rnd_im(gr_ctx_t ctx, int rnd)source
void decimal_ctx_set_rad_prec(gr_ctx_t ctx, slong rad_prec)source
void decimal_ctx_set_exp_limits(gr_ctx_t ctx, slong emin, slong emax)source
void decimal_ctx_set_flags(gr_ctx_t ctx, int flags)source

Changes the default precision, the default rounding mode, the radius precision (clamped to [1, R] where R = DECMAG_MAX_PREC is 9 on a 64-bit machine and 4 on a 32-bit machine), the exponent limits and the flags of a context. Exponent limits apply to the scientific exponent E of a number x, 10^E \le |x| < 10^{E+1}; WORD_MIN and WORD_MAX denote the absence of a limit. All settings can be changed at any time; see Operands and results.

In a complex floating-point context, real parts are rounded in the mode set by decimal_ctx_set_rnd, which also resets the mode for imaginary parts, and decimal_ctx_set_rnd_im subsequently changes the mode for imaginary parts alone. The imaginary rounding mode is ignored in the other contexts.

Through the generics interface, gr_ctx_has_real_prec is true and gr_ctx_set_real_prec and gr_ctx_get_real_prec are supported with the precision measured in bits: setting p bits selects \lceil p \log_{10} 2 \rceil digits, and a context with d digits reports \lfloor d \log_2 10 \rfloor - 1 bits (directed rounding to d digits has a relative error up to 10^{1-d}, slightly more than that of d \log_2 10 bits). This lets generic algorithms that take a precision in bits (series expansions, linear algebra with adaptive precision) work with decimal contexts. Since they assume radix-2 semantics, their results need not be what they would be for binary types, but they remain correct, since all decimal operations return correctly rounded results or rigorous enclosures.

Guides#

Cite this page

The FLINT team, “decimal_ctx_set_prec, decimal_ctx_set_rnd, decimal_ctx_set_rnd_im, decimal_ctx_set_rad_prec, decimal_ctx_set_exp_limits, decimal_ctx_set_flags (decimal.h),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/decimal/decimal_ctx_set_prec.html (generated 2026-10-20).