SetAccuracy[expr,a]
yields a version of expr in which all numbers have been set to have accuracy a.
SetAccuracy
SetAccuracy[expr,a]
yields a version of expr in which all numbers have been set to have accuracy a.
Details
- When SetAccuracy is used to increase the accuracy of a number, the number is padded with zeros. The zeros are taken to be in base 2. In base 10, the additional digits are usually not zeros.
- SetAccuracy returns an arbitrary‐precision number even if the number of significant digits obtained will be less than $MachinePrecision.
- When expr contains machine‐precision numbers, SetAccuracy[expr,a] can give results that differ from one computer system to another.
- SetAccuracy will first expose any hidden extra digits in the internal binary representation of a number, and, only after these are exhausted, add trailing zeros. »
- 0.004``25 generates a number with all trailing digits zero and accuracy 25 on any computer system.
- SetAccuracy[expr,a] does not modify expr itself.
Examples
open all close allBasic Examples (2)
Scope (5)
Set the accuracy of a complex number:
SetAccuracy[Pi + I, 24]Convert approximate numbers to exact rational numbers:
SetAccuracy[f[.1, N[1 / 10, 30], 0.], Infinity]The result has trailing zeros once any hidden digits are exposed:
TableForm[Table[{p, SetAccuracy[3.14, p]}, {p, 15, 65, 5}]]SetAccuracy does not affect exact powers:
p = (x + Pi) ^ (9 / 2)SetAccuracy[p, 18]This allows you to, for example, change the accuracy of polynomial coefficients:
poly = 1. + 2. x + 3. x ^ 2 + 4. x ^ 3;SetAccuracy[poly, 20]SetAccuracy[x ^ 1.25, 20]Special rules may apply to data objects:
ifun = Interpolation[{0, 0, 1, 1}]For an InterpolatingFunction object, SetAccuracy changes the appropriate data only:
spifun = SetAccuracy[ifun, 20]InputForm[spifun]It works as an approximate function, but with arithmetic appropriate for the modified data:
{ifun[5 / 3], spifun[5 / 3]}Applications (1)
Find the roundoff error in evaluating an expression with machine numbers:
e = Hold[(Sin[1.00000000001] - Sin[1.0]) / (1.00000000001 - 1.0)]em = ReleaseHold[e]eb = ReleaseHold[SetAccuracy[e, 32]]eb - emThis dominates the approximation error since the increment is so small:
eb - Cos[1]Properties & Relations (2)
SetAccuracy just sets the precision of numbers, while N works adaptively:
N[Exp[10], {∞, 20}]Since N works adaptively, the result has the requested accuracy of 20:
Accuracy[%]Use SetAccuracy:
SetAccuracy[Exp[10], 20]The accuracy is less than 20 because of the way the exponential function magnifies the result:
Accuracy[%]SetAccuracy effectively evaluates Exp with argument 10 to accuracy 20:
Exp[10``20]For nonzero numbers
, SetAccuracy[x,a] is equivalent to SetPrecision[x,a+e]:
xl = RandomReal[1, 4, WorkingPrecision -> 20] * 10 ^ RandomInteger[{-9, 9}, 4]Map[SetAccuracy[#, 20]&, xl]e is given by RealExponent:
Map[SetPrecision[#, 20 + RealExponent[#]]&, xl]See Also
Tech Notes
Related Guides
History
Introduced in 1991 (2.0)
Text
Wolfram Research (1991), SetAccuracy, Wolfram Language function, https://reference.wolfram.com/language/ref/SetAccuracy.html.
CMS
Wolfram Language. 1991. "SetAccuracy." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/SetAccuracy.html.
APA
Wolfram Language. (1991). SetAccuracy. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SetAccuracy.html
BibTeX
@misc{reference.wolfram_2026_setaccuracy, author="Wolfram Research", title="{SetAccuracy}", year="1991", howpublished="\url{https://reference.wolfram.com/language/ref/SetAccuracy.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_setaccuracy, organization={Wolfram Research}, title={SetAccuracy}, year={1991}, url={https://reference.wolfram.com/language/ref/SetAccuracy.html}, note=[Accessed: 13-June-2026]}