2.2250738585072012e-308
to a double. In theory, the number should be converted to 0x1p-1022
, that is, Double.MIN_VALUE
. However, Java hangs at 0x0.fffffffffffffp-1022
, the largest denormalized number for double. class RuntimeHang { public static void main(String[] args) { System.out.println("Test:"); double d = Double.parseDouble("2.2250738585072012e-308"); System.out.println("Value: " + d); } }
class CompilationHang { public static void main(String[] args) { double d = 2.2250738585072012e-308; System.out.println("Value: " + d); } }
If you comment out this part, there is no longer any hangup inDouble.parseDouble(String s)
, becauseDouble.parseDouble(String s)
, which callssun.misc.FloatingDecimal.readJavaFormatString(s).doubleValue()
is pure java code, nothing native. But it uses artifacts of floating-point numbers, so the matter can be in the compiler settings, which compiled JRE and javac.
Without a correction cycle, such bits (big endian) are output:00000000 00001111 11111111 11111111 11111111 11111111 11111111 11111111
That is, the number is converted to the largest denormalized floating point number, since the exponent is zero. Without a correction cycle, the same thing happens with2.2250738585072013e-308
, however, if you uncomment the cycle, it will convert correctly:00000000 00010000 00000000 00000000 00000000 00000000 00000000 00000000
Source: https://habr.com/ru/post/112948/
All Articles