As the old documentation states:
$EqualTolerance gives the number of decimal digits by which two numbers can disagree and still be considered equal according to Equal.
The default setting is equal to Log[10, 2^7], corresponding to a tolerance of 7 binary digits.
On my system $MachinePrecision
is ~15.9546 which means there are 53 bits:
Log10[2^53] == $MachinePrecision
True
Let's look at the 53 bits of two different machine numbers, a
, and b
:
a = .1234567890123456;
b = .1234567890123453;
Subtract @@ RealDigits[{a, b}, 2, 53] // First
Length @ First @ Split @ %
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, -1, 0, 1}
48
So the first 48 bits are the same and the fifth least significant bit is different.
Internal`$EqualTolerance = N @ Log10[2^4];
a == b
Internal`$EqualTolerance = N @ Log10[2^5];
a == b
False
True
$SameQTolerance
behaves the same only it applies to SameQ
rather than Equal
:
Internal`$SameQTolerance = Log10[2`^4];
a === b
Internal`$SameQTolerance = Log10[2`^5];
a === b
False
True
Arbitrary precision
I realized that my chosen example of machine precision numbers might be misinterpreted. The same mechanism also applies to arbitrary precision numbers. Here we have numbers with 84 binary digits, the first 70 of each being identical meaning the fourteenth least significant digit varies.
a = 1234567.8901234567890123456;
b = 1234567.8901234567890111111;
Subtract @@ RealDigits[{a, b}, 2] // First;
Length @ First @ Split @ %
Length @ %%
70
84
Internal`$EqualTolerance = N@Log10[2^13];
a == b
Internal`$EqualTolerance = N@Log10[2^14];
a == b
False
True