MachinePrecision Numbers

Whenever machineprecision numbers appear in a calculation, the whole calculation is typically done in machine precision. The Wolfram Language will then give machineprecision numbers as the result.

Whenever the input contains any machineprecision numbers, the Wolfram Language does the computation to machine precision.
In[1]:=
Click for copyable input
Out[1]=
Zeta[5.6] yields a machineprecision result, so the N is irrelevant.
In[2]:=
Click for copyable input
Out[2]=
This gives a higherprecision result.
In[3]:=
Click for copyable input
Out[3]=

When you do calculations with arbitraryprecision numbers, as discussed in "ArbitraryPrecision Numbers", the Wolfram Language always keeps track of the precision of your results, and gives only those digits which are known to be correct, given the precision of your input. When you do calculations with machineprecision numbers, however, the Wolfram Language always gives you a machineprecision result, whether or not all the digits in the result can, in fact, be determined to be correct on the basis of your input.

This subtracts two machineprecision numbers.
In[4]:=
Click for copyable input
Out[4]=
The result is taken to have machine precision.
In[5]:=
Click for copyable input
Out[5]=
Here are all the digits in the result.
In[6]:=
Click for copyable input
Out[6]//InputForm=

The fact that you can get spurious digits in machineprecision numerical calculations with the Wolfram Language is in many respects quite unsatisfactory. The ultimate reason, however, that the Wolfram Language uses fixed precision for these calculations is a matter of computational efficiency.

The Wolfram Language is usually set up to insulate you as much as possible from the details of the computer system you are using. In dealing with machineprecision numbers, you would lose too much, however, if the Wolfram Language did not make use of some specific features of your computer.

The important point is that almost all computers have special hardware or microcode for doing floatingpoint calculations to a particular fixed precision. The Wolfram Language makes use of these features when doing machineprecision numerical calculations.

The typical arrangement is that all machineprecision numbers in the Wolfram Language are represented as "doubleprecision floatingpoint numbers" in the underlying computer system. On most current computers, such numbers contain a total of 64 binary bits, typically yielding 16 decimal digits of mantissa.

The main advantage of using the builtin floatingpoint capabilities of your computer is speed. Arbitraryprecision numerical calculations, which do not make such direct use of these capabilities, are usually many times slower than machineprecision calculations.

There are several disadvantages of using builtin floatingpoint capabilities. One already mentioned is that it forces all numbers to have a fixed precision, independent of what precision can be justified for them.

A second disadvantage is that the treatment of machineprecision numbers can vary slightly from one computer system to another. In working with machineprecision numbers, the Wolfram Language is at the mercy of the floatingpoint arithmetic system of each particular computer. If floatingpoint arithmetic is done differently on two computers, you may get slightly different results for machineprecision Wolfram Language calculations on those computers.

$MachinePrecisionthe number of decimal digits of precision
$MachineEpsilonthe minimum positive machineprecision number which can be added to 1.0 to give a result distinguishable from 1.0
$MaxMachineNumberthe maximum machineprecision number
$MinMachineNumberthe minimum positive machineprecision number
$MaxNumberthe maximum magnitude of an arbitraryprecision number
$MinNumberthe minimum magnitude of a positive arbitraryprecision number

Properties of numbers on a particular computer system.

Since machineprecision numbers on any particular computer system are represented by a definite number of binary bits, numbers that are too close together will have the same bit pattern, and so cannot be distinguished. The parameter $MachineEpsilon gives the distance between and the closest number that has a distinct binary representation.

This gives the value of $MachineEpsilon for the computer system on which these examples are run.
In[7]:=
Click for copyable input
Out[7]=
Although this prints as , the Wolfram Language knows that the result is larger than 1.
In[8]:=
Click for copyable input
Out[8]=
InputForm reveals that the result is not exactly 1.
In[9]:=
Click for copyable input
Out[9]//InputForm=
Subtracting 1 gives $MachineEpsilon.
In[10]:=
Click for copyable input
Out[10]=
This prints as also.
In[11]:=
Click for copyable input
Out[11]=
In this case, however, the result is not distinguished from to machine precision.
In[12]:=
Click for copyable input
Out[12]//InputForm=
Subtracting 1 from the result yields 0.
In[13]:=
Click for copyable input
Out[13]=

Machine numbers have not only limited precision, but also limited magnitude. If you generate a number that lies outside the range specified by $MinMachineNumber and $MaxMachineNumber, the Wolfram Language will automatically convert the number to arbitraryprecision form.

This is the maximum machineprecision number that can be handled on the computer system used for this example.
In[14]:=
Click for copyable input
Out[14]=
The Wolfram Language automatically converts any result larger than $MaxMachineNumber to arbitrary precision.
In[15]:=
Click for copyable input
Out[15]=
Here is another computation whose result is outside the range of machine-precision numbers.
In[16]:=
Click for copyable input
Out[16]=