In double precision, you have about 52 binary digits of precision (this translates to the roughly 15 decimal digits), that can scale up and down the exponent "curve"(1). This means that a number made up of powers of two will only be differentiable if all of those powers of two are within that distance from each other (on the curve).
So, 250
and 250 + 2-10
will almost certainly become the same number, because the distance between the two terms of that second number differ by 60 on the curve.
Running the following C code confirms this:
#include <math.h>
#include <stdio.h>
int main(void) {
double d1 = pow(2, 50);
double d2 = d1 + pow(2, -10);
if (d1 == d2) puts("Same");
return 0;
}
In terms of two numbers with 16 decimal digits of precision, that's also doable, as 252
is about 4.5 x 1015
. That doesn't quite reach 1016
so what you need to look for is numbers with mostly zeros but a significant one-bit at the top and bottom of the mantissa.
This can be achieved (in one way) with a 9
at the left, and a 1
at the right, so 9.000000000000001
and 9.000000000000002
:
#include <stdio.h>
int main(void) {
double d1 = 9.000000000000001;
double d1 = 9.000000000000002;
if (d1 == d2) puts("Same");
return 0;
}
(1) By curve here, I mean logarithmic scale, where the distance between 210
and 213
is 3
.
The way a number is constructed is that the mantissa (or fraction) bits create a base number formed by consecutive powers of two. So the bits 101
could create 22 + 20
, or 5
(there's actually an implicit 1
bit at the start in IEEE-754, but we'll ignore that for simplicity).
The exponent bits are then used to scale, or multiply by another power of two, so you could for example, multiply that 5
by 24 = 16
to get 80
, or 2-10 = 1/1024
to get 0.0048828125
.
And, for completeness, the single sign bit then decides whether it's a positive or negative value. Both that, and the various bit patterns that give you special numbers like NaN
and the infinities, are also ignored here because they're not really relevant to the question.
So, in order for a number to be differentiable from another, the most significant and least significant bits must fit within the limited-size mantissa.
See my earlier answer here for more detail on how this all works.