I try to wrap my head around machine precision calculations in Mathematica (11.2, Linux). I do not understand the following behavior:
$MachineEpsilon
2.22045*10^-16
$MachinePrecision
15.9546
2^-46 // N
1.42109*10^-14
N[1 + 2^-46, $MachinePrecision] == 1
True
Why does this statement still evaluate to True? It is so far away from $MachineEpsilon that it should evaluate to False?
Furthermore, why does the following yield a result which is exactly equal to a mantissa of just 46bit? I guess its the same answer and the same question as above.
one = 1;
eps = 1;
SetPrecision[one, prec];
SetPrecision[eps, prec];
For[
SetPrecision[eps = one, MachinePrecision],
SetPrecision[one + eps, MachinePrecision] != 1,
SetPrecision[eps = eps/2, MachinePrecision]
]
eps
1/70368744177664
What I try to understand is what rules Mathematica applies that lead to such results. My problem is that currently I have the impression that I can't rely on SetPrecision[] etc.
Internal`$EqualTolerancewhich controls the tolerance ofEqual. Read more here: https://stackoverflow.com/a/6626748/590388 – Alexey Popkov Aug 14 '18 at 13:13