Is something broken or I fail to understand what is happening?
static String getRealBinary(double val) {
long tmp = Double.doubleToLongBits(val);
StringBuilder sb = new StringBuilder();
for (long n = 64; --n > 0; tmp >>= 1)
if ((tmp & 1) == 0)
sb.insert(0, ('0'));
else
sb.insert(0, ('1'));
sb.insert(0, '[').insert(2, "] [").insert(16, "] [").append(']');
return sb.toString();
}
public static void main(String[] argv) {
for (int j = 3; --j >= 0;) {
double d = j;
for (int i = 3; --i >= 0;) {
d += Double.MIN_VALUE;
System.out.println(d +getRealBinary(d));
}
}
}
With output:
2.0[1] [00000000000] [000000000000000000000000000000000000000000000000000]
2.0[1] [00000000000] [000000000000000000000000000000000000000000000000000]
2.0[1] [00000000000] [000000000000000000000000000000000000000000000000000]
1.0[0] [11111111110] [000000000000000000000000000000000000000000000000000]
1.0[0] [11111111110] [000000000000000000000000000000000000000000000000000]
1.0[0] [11111111110] [000000000000000000000000000000000000000000000000000]
4.9E-324[0] [00000000000] [000000000000000000000000000000000000000000000000001]
1.0E-323[0] [00000000000] [000000000000000000000000000000000000000000000000010]
1.5E-323[0] [00000000000] [000000000000000000000000000000000000000000000000011]