Review: 4396272 - Parsing doubles fails to follow IEEE for largest decimal that should yield 0 (original) (raw)

Brian Burkhalter brian.burkhalter at oracle.com
Fri Feb 15 01:23:46 UTC 2013


The patch below is as submitted to OpenJDK bugzilla but with enhanced comments. It pertains to the correction loop in the doubleValue() method of FloatingDecimal. The situation appears to arise when the candidate value is less than 2Double.MIN_NORMAL as for such values the ULP is less than 2Double.MIN_VALUE so that the intermediate result 0.5*ULP is less than Double.MIN_VALUE which rounds to zero per FP-strict and the correction is therefore zero. Thus the candidate value is unchanged. The fix is to add the ULP to twice the candidate value, obtain the intermediate result, and then halve it to obtain the adjusted candidate.

I am relatively new to IEEE-754 and this area of the code so any comments would be appreciated.

Thanks,

Brian

diff -r 1405ad6afb1e -r 36482ed9bb7e src/share/classes/sun/misc/FloatingDecimal.java --- a/src/share/classes/sun/misc/FloatingDecimal.java Thu Feb 14 11:09:07 2013 -0800 +++ b/src/share/classes/sun/misc/FloatingDecimal.java Thu Feb 14 16:47:53 2013 -0800 @@ -35,8 +35,16 @@ int decExponent; char digits[]; int nDigits; +

@@ -1604,7 +1612,50 @@ } else if ( cmpResult == 0 ){ // difference is exactly half an ULP // round to some other value maybe, then finish

diff -r 1405ad6afb1e -r 36482ed9bb7e test/java/lang/Double/ParseDouble.java --- a/test/java/lang/Double/ParseDouble.java Thu Feb 14 11:09:07 2013 -0800 +++ b/test/java/lang/Double/ParseDouble.java Thu Feb 14 16:47:53 2013 -0800 @@ -23,7 +23,7 @@

/*

@@ -560,17 +560,18 @@ * region that should convert to that value. */ private static void testSubnormalPowers() {

@@ -578,17 +579,52 @@

         double convertedLowerBound = Double.parseDouble(lowerBound.toString());
         double convertedUpperBound = Double.parseDouble(upperBound.toString());

+// final double expected = 0x0.0000008000001p-1022; boolean failed = false; double conversion = 0.0; double sum = 0.0; // Prevent conversion from being optimized away



More information about the core-libs-dev mailing list