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 arbitraryprecision number even if the number of significant digits obtained will be less than $MachinePrecision.
  • When expr contains machineprecision 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 allclose all

Basic Examples  (2)

Set the accuracy of all numbers in an expression to 20:

Convert from a machine number to an arbitrary-precision number with accuracy 32:

Scope  (5)

Set the accuracy of a complex number:

Convert approximate numbers to exact rational numbers:

The result has trailing zeros once any hidden digits are exposed:

SetAccuracy does not affect exact powers:

This allows you to, for example, change the accuracy of polynomial coefficients:

Inexact powers are modified:

Special rules may apply to data objects:

For an InterpolatingFunction object, SetAccuracy changes the appropriate data only:

It works as an approximate function, but with arithmetic appropriate for the modified data:

Applications  (1)

Find the roundoff error in evaluating an expression with machine numbers:

This dominates the approximation error since the increment is so small:

Properties & Relations  (2)

SetAccuracy just sets the precision of numbers, while N works adaptively:

Since N works adaptively, the result has the requested accuracy of 20:

Use SetAccuracy:

The accuracy is less than 20 because of the way the exponential function magnifies the result:

SetAccuracy effectively evaluates Exp with argument 10 to accuracy 20:

For nonzero numbers , SetAccuracy[x,a] is equivalent to SetPrecision[x,a+e]:

e is given by RealExponent:

Wolfram Research (1991), SetAccuracy, Wolfram Language function, https://reference.wolfram.com/language/ref/SetAccuracy.html.

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_2023_setaccuracy, author="Wolfram Research", title="{SetAccuracy}", year="1991", howpublished="\url{https://reference.wolfram.com/language/ref/SetAccuracy.html}", note=[Accessed: 19-March-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_setaccuracy, organization={Wolfram Research}, title={SetAccuracy}, year={1991}, url={https://reference.wolfram.com/language/ref/SetAccuracy.html}, note=[Accessed: 19-March-2024 ]}