The precision limit on double causes the binary representation to round to the nearest power of 2 , which increases the exponent in the floating point representation of the double value. This is because the double mantissa, including implied bit 1 , is 53 bits, but long has 64 bits.
JLS Section 5.1.2 describes what can happen in this expanding primitive transformation:
An expanding primitive conversion from int to float or from long to float or from long to double can lead to a loss of precision - that is, the result may lose some of the least significant bits of the value. In this case, the resulting floating point value will be a correctly rounded version of the integer value using the round-nearest mode of IEEE 754 (Β§4.2.4).
(my emphasis)
Here I use Double.doubleToLongBits to store the double bits in long and Long.toHexString to print the hexadecimal values ββof the original double s.
System.out.format("Max(%s): %-5d Min(%s): %-5d -1(%s): %-5d%n", Long.toHexString(Double.doubleToLongBits(dmax)), Math.getExponent(dmax), Long.toHexString(Double.doubleToLongBits(dmax)), Math.getExponent(dmin), Long.toHexString(Double.doubleToLongBits(dneg)), Math.getExponent(dneg));
Output:
Max(43e0000000000000): 63 Min(43e0000000000000): 63 -1(bff0000000000000): 0 Max(43d0000000000000): 62 Min(43d0000000000000): 62 -1(43e0000000000000): 63 Max(43c0000000000000): 61 Min(43c0000000000000): 61 -1(43d0000000000000): 62 Max(43b0000000000000): 60 Min(43b0000000000000): 60 -1(43c0000000000000): 61 Max(43a0000000000000): 59 Min(43a0000000000000): 59 -1(43b0000000000000): 60 Max(4390000000000000): 58 Min(4390000000000000): 58 -1(43a0000000000000): 59 Max(4380000000000000): 57 Min(4380000000000000): 57 -1(4390000000000000): 58 Max(4370000000000000): 56 Min(4370000000000000): 56 -1(4380000000000000): 57 Max(4360000000000000): 55 Min(4360000000000000): 55 -1(4370000000000000): 56 Max(4350000000000000): 54 Min(4350000000000000): 54 -1(4360000000000000): 55 Max(433fffffffffffff): 52 Min(433fffffffffffff): 53 -1(4350000000000000): 54 Max(432ffffffffffffe): 51 Min(432ffffffffffffe): 52 -1(433fffffffffffff): 52
Original long values ββwith more than 53 1 bits are rounded when converted to double , losing precision. The exponent field consists of bits 2 through 12 , visible in the first three hexadecimal digits printed above.
When a value shifts below 53 1 bit, the precision of double now sufficient to hold the value without rounding (rounding is no longer required), and the mantissa bits become visible as "f" hexadecimal digits. There is a gap in the exponent field going from 435 to 433 , explaining why there is a gap as a result of Math.getExponent , from 54 to 52 .