Request for sponsor: 4421494 infinite loop while parsing double literal

Dmitry Nadezhin Dmitry.Nadezhin at Sun.COM
Thu Nov 5 21:07:33 UTC 2009


http://bugs.sun.com/view_bug.do?bug_id=4421494
https://bugs.openjdk.java.net/show_bug.cgi?id=100119

Summary: This old bug report says that Double.parseDouble(s) hangs for decimal strings
in range (Double.MIN_NORMAL-0.5*Double.MIN_VALUE,Double.MIN), and returns
incorrect result for decimal string Double.MIN_NORMAL-0.5*Double.MIN_VALUE.

This is because current code in FloatingDecimal.doubleValue() incorrectly
defines the condition when nextDown(dValue) - dValue == -0.5*ulp(dValue). The
current code considers that these are all numbers 2^n which are represented as
normal doubles, and nexDown(dValue) - dValue == -1.0*ulp(dValue) for other
doubles (subnormal or not 2-powers).
However, this is not correct for dValue == Double.MIN_VALUE, because
nextDown(Double.MIN_NORMAL) - Double.MIN_NORMAL == -1.0*ulp(Double.MIN_NORMAL).

The suggested change
-                    if ( (bigIntNBits == 1) && (bigIntExp > -expBias) ){
+                    if ( (bigIntNBits == 1) && (bigIntExp > -expBias+1) ){
redefines the condition so that dValue == Double.MIN_NORMAL doesn't satisfy it.

 -Dima







More information about the core-libs-dev mailing list