Machine-Precision Numbers

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

Whenever the input contains any machine-precision numbers, the Wolfram Language does the computation to machine precision:

1.4444444444444444444^5.7

(RefLink[Zeta, paclet:ref/Zeta])[5.6] yields a machine-precision result, so the (RefLink[N, paclet:ref/N]) is irrelevant:

N[Zeta[5.6],30]

This gives a higher-precision result:

N[Zeta[56/10],30]

When you do calculations with arbitrary-precision numbers, as discussed in "Arbitrary-Precision 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 machine-precision numbers, however, the Wolfram Language always gives you a machine-precision 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 machine-precision numbers:

diff=1.11111111-1.11111000

The result is taken to have machine precision:

Precision[diff]

Here are all the digits in the result:

InputForm[diff]

The fact that you can get spurious digits in machine-precision 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 machine-precision 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 floating-point calculations to a particular fixed precision. The Wolfram Language makes use of these features when doing machine-precision numerical calculations.

The typical arrangement is that all machine-precision numbers in the Wolfram Language are represented as "double-precision floating-point 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 built-in floating-point capabilities of your computer is speed. Arbitrary-precision numerical calculations, which do not make such direct use of these capabilities, are usually many times slower than machine-precision calculations.

There are several disadvantages of using built-in floating-point 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 machine-precision numbers can vary slightly from one computer system to another. In working with machine-precision numbers, the Wolfram Language is at the mercy of the floating-point arithmetic system of each particular computer. If floating-point arithmetic is done differently on two computers, you may get slightly different results for machine-precision Wolfram Language calculations on those computers.

Properties of numbers on a particular computer system.

Since machine-precision 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 (RefLink[$MachineEpsilon, paclet:ref/$MachineEpsilon]) gives the distance between 1.0 and the closest number that has a distinct binary representation.

This gives the value of (RefLink[$MachineEpsilon, paclet:ref/$MachineEpsilon]) for the computer system on which these examples are run:

$MachineEpsilon

Although this prints as 1., the Wolfram Language knows that the result is larger than 1:

1.+$MachineEpsilon

(RefLink[InputForm, paclet:ref/InputForm]) reveals that the result is not exactly 1:

%//InputForm

Subtracting 1 gives (RefLink[$MachineEpsilon, paclet:ref/$MachineEpsilon]):

%-1.

This prints as 1. also:

1.+$MachineEpsilon/2

In this case, however, the result is not distinguished from 1. to machine precision:

%//InputForm

Subtracting 1 from the result yields 0:

%-1.

Machine numbers have not only limited precision, but also limited magnitude. If you generate a number that is larger in magnitude than (RefLink[$MaxMachineNumber, paclet:ref/$MaxMachineNumber]), the Wolfram Language will automatically convert the number to arbitrary-precision form.

This is the maximum machine-precision number that can be handled on the computer system used for this example:

$MaxMachineNumber

The Wolfram Language automatically converts any result larger than (RefLink[$MaxMachineNumber, paclet:ref/$MaxMachineNumber]) to arbitrary precision:

2 $MaxMachineNumber

Here is another computation whose result is outside the range of machine-precision numbers:

Exp[1000.]

As of Version 11.3, if a machine-precision computation generates a number that is smaller in magnitude than (RefLink[$MinMachineNumber, paclet:ref/$MinMachineNumber]), the Wolfram Language will issue a warning. However, it will retain the result as a subnormal machine number that has leading zeros in its binary significand.

This is the minimum machine-precision number that can be put into normal form on the computer system used for this example:

$MinMachineNumber

The Wolfram Language issues warnings about computations that produce numbers smaller than (RefLink[$MinMachineNumber, paclet:ref/$MinMachineNumber]), but it does not automatically convert to arbitrary-precision arithmetic:

$MinMachineNumber/2^52

It is possible to lose all significant digits and end up with a machine zero answer:

$MinMachineNumber/2^53

Converting to arbitrary precision using (RefLink[SetPrecision, paclet:ref/SetPrecision]) can avoid this underflow:

SetPrecision[$MinMachineNumber,$MachinePrecision]/2^53