FLINT3.7.0-dev

decfloat_set, decfloat_set_si, decfloat_set_ui, decfloat_set_fmpz, decfloat_set_fmpq, decfloat_set_d, decfloat_set_str, decfloat_set_arf, decfloat_set_fmpz_10exp_fmpz, decfloat_set_fmpz_10exp_si, decfloat_set_si_10exp_si, decfloat_set_fmpz_2exp_fmpz, decfloat_set_other

Synopsis#include <flint/decimal.h>
int decfloat_set(decfloat_t res, const decfloat_t x, gr_ctx_t ctx)source
int decfloat_set_si(decfloat_t res, slong x, gr_ctx_t ctx)source
int decfloat_set_ui(decfloat_t res, ulong x, gr_ctx_t ctx)source
int decfloat_set_fmpz(decfloat_t res, const fmpz_t x, gr_ctx_t ctx)source
int decfloat_set_fmpq(decfloat_t res, const fmpq_t x, gr_ctx_t ctx)source
int decfloat_set_d(decfloat_t res, double x, gr_ctx_t ctx)source
int decfloat_set_str(decfloat_t res, const char * s, gr_ctx_t ctx)source
int decfloat_set_arf(decfloat_t res, const arf_t x, gr_ctx_t ctx)source
int decfloat_set_fmpz_10exp_fmpz(decfloat_t res, const fmpz_t m, const fmpz_t e, gr_ctx_t ctx)source
int decfloat_set_fmpz_10exp_si(decfloat_t res, const fmpz_t m, slong e, gr_ctx_t ctx)source
int decfloat_set_si_10exp_si(decfloat_t res, slong m, slong e, gr_ctx_t ctx)source
int decfloat_set_fmpz_2exp_fmpz(decfloat_t res, const fmpz_t m, const fmpz_t e, gr_ctx_t ctx)source
int decfloat_set_other(decfloat_t res, gr_srcptr x, gr_ctx_t x_ctx, gr_ctx_t ctx)source

Set res to the given value, correctly rounded to the context precision in the context rounding mode. Strings may be plain decimal literals ("-12.5e-3", "inf", "nan") or arithmetic expressions ("1/3"), the latter evaluated by the generic expression parser with every operation rounded. decfloat_set_other converts elements of other rings.

Binary values m 2^k are converted with exact integer arithmetic on a scaled truncation of the value (the digits needed plus guard digits, and a sticky bit) when the sizes are moderate, and otherwise (huge |k|, or a huge mantissa) by scaling with a power of ten in arb arithmetic combined with Ziv's strategy, after checking whether the value is an exact decimal number of at most prec digits (which Ziv's strategy could not decide); this is correctly rounded in all cases, with a cost essentially linear in the size of k for huge exponents. set_other accepts integers, rationals, arf, arb and acb values (through their midpoints, with GR_UNABLE for an inexact ball when the target precision is exact), elements of all the decimal rings (balls likewise through their midpoints; complex values must have a zero imaginary part or GR_DOMAIN is returned), algebraic numbers (qqbar, see decfloat_set_qqbar), and elements of other rings through a conversion to acb at a somewhat higher precision, which is not correctly rounded.

Guides#

Cite this page

The FLINT team, “decfloat_set, decfloat_set_si, decfloat_set_ui, decfloat_set_fmpz, decfloat_set_fmpq, decfloat_set_d, decfloat_set_str, decfloat_set_arf, decfloat_set_fmpz_10exp_fmpz, decfloat_set_fmpz_10exp_si, decfloat_set_si_10exp_si, decfloat_set_fmpz_2exp_fmpz, decfloat_set_other (decimal.h),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/decimal/decfloat_set.html (generated 2026-10-20).