SetPrecision¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
SetPrecision[x, n]
Returns an expression equivalent to x with numeric values
re-rounded or promoted to n decimal digits of precision.
Requires a USE_MPFR build for n > MachinePrecision.
Examples¶
No verified examples yet for this function.
Implementation notes¶
builtin_set_precision is a two-argument wrapper: it parses the precision argument into a NumericSpec via parse_prec_arg (accepting an integer/real digit count or MachinePrecision) and drives numericalize(value, spec) — the same engine N uses — to re-represent the value to the requested number of significant digits (an EXPR_MPFR at the corresponding bit width when MPFR is built, otherwise machine double). Returns NULL if the precision argument is not a valid spec.
Attributes: Listable, Protected.
Implementation status¶
Stable — documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
References¶
- Source:
src/precision.c - Specification:
docs/spec/builtins/arithmetic.md
Notes & additional examples¶
Worked examples¶
Applied to an exact constant, SetPrecision produces a high-precision numeric
value — here 50 correct digits of Pi:
It also re-rounds an exact rational to a chosen precision; note the trailing digit shows where the finite expansion is cut off:
Notes¶
SetPrecision[x, n] returns a value equal to x but carrying n digits of precision; the printed form may look unchanged while the internal precision is raised (confirm with Precision). Padding extra digits onto a machine-precision number introduces meaningless trailing bits, so only widen precision when the original value genuinely has them.