I want to play around a bit in Mathematica to understand how floating-point precision, rounding and truncation actually works. I understand that Machineprecision is $2^{-52}$.
First of all I would like to create a binarynumber and show that it is correct until the machinecorrection and after that it starts to be 'random'. But how do I do this? For example:
BaseForm[1/3 // N, 2]
Generates: $0.010101010101010101011_2$
- Why are there $21$ digits after the dot?
- Why not $52$? How can I get $52$?
- How can I show this number in the form the computer stores it? That is, with an exponent and a mantissa?
- How to show what happens to a number beyond machineprecision?
This is all quite new to me, so any help is appreciated. I am sorry for the lack of knowledge.
Maybe in other words, I firstly try to understand why this code:
BaseForm[1 + $MachineEpsilon, 2]
Doesn't generate a binary number with $52$ digits.
BaseForm
is being applied to the "standard" form, which truncates to 6 decimal digits. (2) FIrst applyInputForm
:In[117]:= BaseForm[InputForm[N[1/3]], 2] Out[117]//BaseForm= \!\( TagBox[ InterpretationBox[ StyleBox["2^^0.010101010101010101010101010101010101010101010101010101", ShowStringCharacters->True, NumberMarks->True], InputForm[0.3333333333333333], AutoDelete->True, Editable->True], BaseForm[#, 2]& ]\)
(3) CheckRealDigits
(4) It falls off the end of the Earth. $\endgroup$ – Daniel Lichtblau Dec 4 '16 at 16:11N[...,prec]
withprec
set to something larger than$MachinePrecision
. $\endgroup$ – Daniel Lichtblau Dec 4 '16 at 17:04