Mathematica internal number formats and precision

一曲冷凌霜 提交于 2019-12-04 07:15:41
Daniel Lichtblau

If I understand correctly you are wondering as to when the InputForm will show more than 6 digits. If so, it happens haphazardly, whenever more digits are required to "best" represent the number obtained after evaluation. Since the evaluation involves explicit multiplication by 10^(some power), and since the decimal input need not be (and in this case is not) exactly representable in binary, you can get small differences from what you expect.

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, that's effectively a parsing (actually lexical) construct. No explicit exact power of 10 is computed. A floating point value is constructed and it is faithful as possible, to the extent allowed by binary-to-decimal, to your input. The InputForm will show as many digits as were used in inputting the number, because that is indeed the closest decimal to the corresponding binary value that got created.

When you surpass the limitations of machine floating point numbers, you get an arbitrary precision analog. It no longer is machinePrecision but actually is $MachinePrecision (that's the bignum analog to machine floats in Mathematica).

What you see in InputForm for 3.12987*^-596 (a decimal ending with a slew of 9's) is, I believe, caused by Mathematica's internal representation involving usage of guard bits. Were there only 53 mantissa bits, analogous to a machine double, then the closest decimal representation would be the expected six digits.

Daniel Lichtblau Wolfram Research

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!