This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

SetPrecision

SetPrecision
yields a version of expr in which all numbers have been set to have precision p.
  • When SetPrecision is used to increase the precision 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.
  • If expr contains machine-precision numbers, SetPrecision can give results that differ from one computer system to another.
  • SetPrecision will first expose any hidden extra digits in the internal binary representation of a number, and, only after these are exhausted, add trailing zeros. »
  • generates a number with all trailing digits zero and precision 25 on any computer system.
Convert all numbers in an expression to 20-digit precision:
Convert all numbers to machine precision:
Convert from a machine number to an arbitrary-precision number:
Convert all numbers in an expression to 20-digit precision:
In[1]:=
Click for copyable input
Out[1]=
 
Convert all numbers to machine precision:
In[1]:=
Click for copyable input
Out[1]=
 
Convert from a machine number to an arbitrary-precision number:
In[1]:=
Click for copyable input
Out[1]=
Set precision of a complex number:
Convert approximate numbers to exact rational numbers:
The result has trailing zeros once any hidden digits are exposed:
SetPrecision does not affect exact powers:
This allows you to, for example, change the precision of polynomial coefficients:
Inexact powers are modified:
Special rules may apply to data objects:
For an InterpolatingFunction object, SetPrecision changes the appropriate data only:
It still works as an approximate function, but with the new precision:
Find the roundoff error in evaluating an expression with machine numbers:
This dominates the approximation error since the increment is so small:
Find the representation error of a machine number:
The error is small because this is the closest machine number to :
The distance between nearest machine numbers is a power of two:
Raise the precision of coefficients in a differential equation to check error:
Find the solutions computed at machine precision and precision 32:
Plot the two solutions. They have deviated by , indicating significant error:
Override the default accuracy and precision model:
This loses precision more slowly than the default model that treats operations as independent:
Nonetheless, all digits given are correct:
The bit loss per iteration is justified because the map is effectively a shift map:
SetPrecision just sets the precision of numbers while N works adaptively:
Since N works adaptively, the result has the requested precision of 20:
The precision is less than 20 because of the conditioning of the sine function at 1000:
SetPrecision effectively evaluates Sin with argument 1000 to precision 20:
N will typically not raise the precision of an expression, while SetPrecision will:
For nonzero numbers , SetPrecision is equivalent to SetAccuracy:
is given by RealExponent:
SetPrecision and Rationalize give rational approximations for real x:
Rationalize gives a rational that is equivalent to x up to the precision of x:
SetPrecision gets a rational directly from the bitwise representation of x:
SetPrecision and RootApproximant[x] give exact approximations for real x:
RootApproximant[x] gives an algebraic number equivalent to x up to the precision of x:
SetPrecision gets a rational directly from the bitwise representation of x:
SetPrecision will make an exact zero for approximate zeros z:
If you want an approximate zero, use SetAccuracy:
The only exception to this is that when prec is MachinePrecision, you get a machine zero:
New in 2 | Last modified in 5