MAX_VALUE is (2 − 2⁻⁵²) × 2¹⁰²³ and MIN_VALUE is 2⁻¹⁰⁷⁴, so if you divide the two you get approx; 2²⁰⁹⁸ which will overflow.[edit]Corrected superscripts and add a minus superscript.That JLS section wrote:If the magnitude of the quotient is too large to represent, we say the operation overflows; the result is then an infinity of appropriate sign.
The Java programming language requires that floating-point arithmetic behave as if every floating-point operator rounded its floating-point result to the result precision. Inexact results must be rounded to the representable value nearest to the infinitely precise result; if the two nearest representable values are equally near, the one with its least significant bit zero is chosen. This is the IEEE 754 standard's default rounding mode known as round to nearest.
More likely that the 1.0 is shifted so its exponent is the same as MAX_VALUE, and the solitary 1 bit is shifted so far to the right that even an extended exponent representation will come out as 0.F Turner wrote:. . . In the case of Double.MAX_VALUE + 1, I doubt that there is any intermediate representation with adequate precision to be able to store this number, so is it just known that such a number could not be stored as a double before the calculation takes place and it is not even attempted?
As you showed it, the IEEE754 format imputes a 53rd 1 bit to the left end of the number. So a double in its normal range uses 53 bits' precision.. . . a double has a mantissa of 52 binary bits.
1.000000000000001 [decimal] = 1.{0000000000|0000000000|0000000000|0000000000|0000000001|00}1000000011 [binary], and
1.0000000000000001 [decimal] = 1.{0000000000|0000000000|0000000000|0000000000|0000000000|00}0111001101 [binary]
Yes; 1.0000000000000001 can only be repesented as a double identical to 1.0.. . . Would this explain why (2) gives Double.MAX_VALUE - because it simply sees the multiplicand as 1.0 since it is beyond the precision of a double, . . .
No problems about the many questions. Yes, that value will be recorded as 1.0 before the calculation is attempted. Multiplication by the slightly larger value will cause an overflow irrespective of how many additional bits are used in the intermediate representation, because the result of the calculation will be reduced to 64 bits. Use the javap tool to see what is happening:-The value of X is shown at number 5.This doesn't conform with the idea of an intermediate higher precision value at first, but I suppose that the program would have to store (2)'s multiplicand before even doing the calculation, at which point it would be interpreted as the double 1.0?
Thanks, and sorry for the endless questions :P
The happiness of your life depends upon the quality of your thoughts -Marcus Aurelius ... think about this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|