Mathematica internal number formats and precision

Tangentially related to this question, what exactly happens with number formatting?

In[1] := InputForm @ 3.12987*10^-270 Out[1] := 3.12987`*^-270 In[2] := InputForm @ 3.12987*10^-271 Out[2] := 3.1298700000000003`*^-271 

If you use *10.^ as a multiplier, the transition is where you would naively expect this:

 In[3] := InputForm @ 3.12987*10.^-16 Out[3] := 3.12987`*^-16 In[4] := InputForm @ 3.12987*10.^-17 Out[4] := 3.1298700000000004`*^-17 

while *^ performs the transition a little further, although this means that the accuracy of the machine begins to split:

 In[5] := InputForm @ 3.12987*^-308 Out[5] := 3.12987`*^-308 In[6] := InputForm @ 3.12987*10.^-309 Out[6] := 3.12987`15.954589770191008*^-309 

The base begins to break only much later

 In[7] := InputForm @ 3.12987*^-595 Out[7] := 3.12987`15.954589770191005*^-595 In[8] := InputForm @ 3.12987*^-596 Out[8] := 3.1298699999999999999999999999999999999999`15.954589770191005*^-596 

I assume that these transitions refer to a format in which Mathematica internally holds it in numbers, but does anyone know or care about making it dangerous to understand how?

+5
wolfram-mathematica number-formatting
source share
1 answer

If I understand correctly, you are wondering when the InputForm will display more than 6 digits. If so, this happens by chance, whenever more digits are required in order to "best" represent the number obtained after the evaluation. Since the evaluation involves explicitly multiplying by 10 ^ (some power), and since the decimal input does not have to be (and in this case is not), which is accurately represented in binary terms, you can get slight differences from the expected one.

 In[26]:= Table[3.12987*10^-j, {j, 10, 25}] // InputForm Out[26]//InputForm= {3.12987*^-10, 3.12987*^-11, 3.12987*^-12, 3.12987*^-13, 3.12987*^-14, 3.12987*^-15, 3.12987*^-16, 3.1298700000000004*^-17, 3.1298700000000002*^-18, 3.12987*^-19, 3.12987*^-20, 3.1298699999999995*^-21, 3.1298700000000003*^-22, 3.1298700000000004*^-23, 3.1298700000000002*^-24, 3.1298699999999995*^-25} 

As for the input syntax * ^, this is an efficiently syntactic (in fact lexical) construction. The explicit exact power is not calculated 10. A floating point value is constructed, and it is as accurate as possible, binary-decimal, to your input. The InputForm will display as many digits as were used when entering the number, because it is really the closest decimal character to the corresponding binary value that was created.

When you exceed the limits of the number of floating-point numbers of a machine, you get an arbitrary precision analogue. It is no longer machine precision, but is actually $ MachinePrecision (which the bignum analog for a machine floats in Mathematica).

What you see in InputForm for 3.12987 * ^ - 596 (decimal ending with the number 9), in my opinion, is caused by the internal representation of Mathematica using the protection bits. There were only 53 bits of the mantissa, similar to doubling the machine, then the nearest decimal representation would be the expected six digits.

Daniel Lichtblow Wolfram Research

+8
source share

All Articles