JDK-7086710 : java/util/Formatter/Basic.java failing after 7082971
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.math
  • Affected Version: 8
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-09-03
  • Updated: 2013-01-31
  • Resolved: 2012-05-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8 b06Fixed
Related Reports
Relates :  
Relates :  
Description
java/util/Formatter/Basic.java is currently failing with builds of jdk8/tl. Seems to stem from the performance work in 7082971. Passes with -XX:+AgressiveOpts which demonstrates that this issue didn't exist with the BigDecimal implementation in alt-rt.jar.


FAILED: '%s': Expected '3.141592653589793115997963468544185161590576171875', got '14148475504056880'
FAILED: '%e': Expected '3.141593e+00', got '1.414848e+16'
FAILED: '%E': Expected '3.141593E+00', got '1.414848E+16'
FAILED: '%10.3e': Expected ' 3.142e+00', got ' 1.415e+16'
FAILED: '%10.3e': Expected '-3.142e+00', got '-1.415e+16'
FAILED: '%010.3e': Expected '03.142e+00', got '01.415e+16'
FAILED: '%010.3e': Expected '-3.142e+00', got '-1.415e+16'
FAILED: '%-12.3e': Expected '3.142e+00   ', got '1.415e+16   '
FAILED: '%-12.3e': Expected '-3.142e+00  ', got '-1.415e+16  '
FAILED: '%.3e': Expected '3.142e+00', got '1.415e+16'
FAILED: '%.3e': Expected '-3.142e+00', got '-1.415e+16'
FAILED: '%.3e': Expected '3.142e+06', got '6.372e+37'
FAILED: '%.3e': Expected '-3.142e+06', got '-6.372e+37'
FAILED: '%e': Expected '3,141593e+00', got '1,414848e+16'
FAILED: '%.3e': Expected '1.396e+149', got '1.633e+4845'
FAILED: '%.3e': Expected '-1.396e+149', got '-1.633e+4845'
FAILED: '%+.3e': Expected '+3.142e+00', got '+1.415e+16'
FAILED: '%+.3e': Expected '-3.142e+00', got '-1.415e+16'
FAILED: '% .3e': Expected ' 3.142e+00', got ' 1.415e+16'
FAILED: '% .3e': Expected '-3.142e+00', got '-1.415e+16'
FAILED: '%#.0e': Expected '3.e+00', got '1.e+16'
FAILED: '%#.0e': Expected '-3.e+00', got '-1.e+16'
FAILED: '%.0e': Expected '3e+00', got '1e+16'
FAILED: '%.0e': Expected '-3e+00', got '-1e+16'
FAILED: '%(.4e': Expected '3.1416e+06', got '6.3719e+37'
FAILED: '%(.4e': Expected '(3.1416e+06)', got '(6.3719e+37)'
FAILED: '%f': Expected '3.141593', got '14148475504056880.000000'
FAILED: '%f': Expected '3,141593', got '14148475504056880,000000'
FAILED: '%10.3f': Expected '     3.142', got '14148475504056880.000'
FAILED: '%10.3f': Expected '    -3.142', got '-14148475504056880.000'
FAILED: '%010.3f': Expected '000003.142', got '14148475504056880.000'
FAILED: '%010.3f': Expected '-00003.142', got '-14148475504056880.000'
FAILED: '%-10.3f': Expected '3.142     ', got '14148475504056880.000'
FAILED: '%-10.3f': Expected '-3.142    ', got '-14148475504056880.000'
FAILED: '%.3f': Expected '3.142', got '14148475504056880.000'
FAILED: '%.3f': Expected '-3.142', got '-14148475504056880.000'
FAILED: '%+.3f': Expected '+3.142', got '+14148475504056880.000'
FAILED: '%+.3f': Expected '-3.142', got '-14148475504056880.000'
FAILED: '% .3f': Expected ' 3.142', got ' 14148475504056880.000'
FAILED: '% .3f': Expected '-3.142', got '-14148475504056880.000'
FAILED: '%#.0f': Expected '3.', got '13510798882111488.'
FAILED: '%#.0f': Expected '-3.', got '-13510798882111488.'
FAILED: '%.0f': Expected '3', got '13510798882111488'
FAILED: '%.0f': Expected '-3', got '-13510798882111488'
FAILED: '%.3f': Expected '3141592.654', got '63719069007931155335134817812480000000.000'
FAILED: '%.3f': Expected '-3141592.654', got '-63719069007931155335134817812480000000.000'
FAILED: '%,.4f': Expected '3,141,592.6536', got '63,719,069,007,931,155,335,134,817,812,480,000,000.0000'
FAILED: '%,.4f': Expected '3?141?592,6536', got '63?719?069?007?931?155?335?134?817?812?480?000?000,0000'
FAILED: '%,.4f': Expected '-3,141,592.6536', got '-63,719,069,007,931,155,335,134,817,812,480,000,000.0000'
FAILED: '%(.4f': Expected '3141592.6536', got '63719069007931155335134817812480000000.0000'
FAILED: '%(.4f': Expected '(3141592.6536)', got '(63719069007931155335134817812480000000.0000)'
FAILED: '%(,.4f': Expected '3,141,592.6536', got '63,719,069,007,931,155,335,134,817,812,480,000,000.0000'
FAILED: '%(,.4f': Expected '(3,141,592.6536)', got '(63,719,069,007,931,155,335,134,817,812,480,000,000.0000)'
FAILED: '%g': Expected '3.14159', got '1.41485e+16'
FAILED: '%g': Expected '3,14159', got '1,41485e+16'
FAILED: '%G': Expected '3.14159', got '1.41485E+16'
FAILED: '%10.3g': Expected '      3.14', got '  1.41e+16'
FAILED: '%10.3g': Expected '     -3.14', got ' -1.41e+16'
FAILED: '%010.3g': Expected '0000003.14', got '001.41e+16'
FAILED: '%010.3g': Expected '-000003.14', got '-01.41e+16'
FAILED: '%-12.3g': Expected '3.14        ', got '1.41e+16    '
FAILED: '%-12.3g': Expected '-3.14       ', got '-1.41e+16   '
FAILED: '%.3g': Expected '3.14', got '1.41e+16'
FAILED: '%.3g': Expected '-3.14', got '-1.41e+16'
FAILED: '%.3g': Expected '3.14e+08', got '6.37e+39'
FAILED: '%.3g': Expected '-3.14e+08', got '-6.37e+39'
FAILED: '%.3g': Expected '1.00e-05', got '2.22e-21'
FAILED: '%.3g': Expected '-1.00e-05', got '-2.22e-21'
FAILED: '%.0g': Expected '-1e-05', got '-2e-21'
FAILED: '%.0g': Expected '1e+05', got '5e+20'
FAILED: '%.3G': Expected '1.00E-05', got '2.22E-21'
FAILED: '%.3G': Expected '-1.00E-05', got '-2.22E-21'
FAILED: '%.3g': Expected '1.40e+149', got '1.63e+4845'
FAILED: '%.3g': Expected '-1.40e+149', got '-1.63e+4845'
FAILED: '%.3g': Expected '-1,40e+149', got '-1,63e+4845'
FAILED: '%+10.3g': Expected '     +3.14', got ' +1.41e+16'
FAILED: '%+10.3g': Expected '     -3.14', got ' -1.41e+16'
FAILED: '% .3g': Expected ' 3.14', got ' 1.41e+16'
FAILED: '% .3g': Expected '-3.14', got '-1.41e+16'
FAILED: '%.0g': Expected '3', got '1e+16'
FAILED: '%.0g': Expected '-3', got '-1e+16'
FAILED: '%(.4g': Expected '3.142e+08', got '6.372e+39'
FAILED: '%(.4g': Expected '(3.142e+08)', got '(6.372e+39)'
FAILED: '%,.11g': Expected '3,141,592.6536', got '6.3719069008e+37'
FAILED: '%(,.11g': Expected '(3,141,592.6536)', got '(6.3719069008e+37)'
Exception in thread "main" java.lang.RuntimeException: 6249 tests: 85 failure(s), first
        at Basic.main(Basic.java:100)
Caused by: java.lang.RuntimeException: '%s': Expected '3.141592653589793115997963468544185161590576171875', got '14148475504056880'
        at Basic.setFirst(Basic.java:64)
        at Basic.fail(Basic.java:57)
        at Basic.ck(Basic.java:72)
        at BasicBigDecimal.test(BasicBigDecimal.java:54)
        at BasicBigDecimal.test(BasicBigDecimal.java:843)
        at Basic.main(Basic.java:95)

Comments
SUGGESTED FIX # HG changeset patch # User darcy # Date 1315235044 25200 # Node ID 43880d125b790009a73a4f72a97a287f3c2cfaa7 # Parent 946e3b786d2d7791cb96e3ab734de15fe04e1c07 7086710: java/util/Formatter/Basic.java failing after 7082971 Reviewed-by: alanb --- a/src/share/classes/java/math/BigDecimal.java Mon Sep 05 11:28:23 2011 +0100 +++ b/src/share/classes/java/math/BigDecimal.java Mon Sep 05 08:04:04 2011 -0700 @@ -904,12 +904,13 @@ public class BigDecimal extends Number i throw new NumberFormatException("Infinite or NaN"); // Translate the double into sign, exponent and significand, according // to the formulae in JLS, Section 20.10.22. - int sign = (val >= 0.0 ? 1 : -1); // Preserving sign of zero doesn't matter - int exponent = Math.getExponent(val); long valBits = Double.doubleToLongBits(val); - long significand = (exponent == (Double.MIN_EXPONENT-1) - ? (valBits & ((1L << 52) - 1)) << 1 - : (valBits & ((1L << 52) - 1)) | (1L << 52)); + int sign = ((valBits >> 63) == 0 ? 1 : -1); + int exponent = (int) ((valBits >> 52) & 0x7ffL); + long significand = (exponent == 0 + ? (valBits & ((1L << 52) - 1)) << 1 + : (valBits & ((1L << 52) - 1)) | (1L << 52)); + exponent -= 1075; // At this point, val == sign * significand * 2**exponent. /* @@ -933,9 +934,7 @@ public class BigDecimal extends Number i BigInteger intVal; long compactVal = sign * significand; if (exponent == 0) { - // If the exponent is zero, the significant fits in a long - assert compactVal != INFLATED; - intVal = null; + intVal = (compactVal == INFLATED) ? INFLATED_BIGINT : null; } else { if (exponent < 0) { intVal = BigInteger.valueOf(5).pow(-exponent).multiply(compactVal); @@ -4162,15 +4161,30 @@ public class BigDecimal extends Number i return qsign < 0; default: // Some kind of half-way rounding - if (roundingMode == ROUND_HALF_DOWN || - cmpFracHalf < 0 ) // We're closer to higher digit + assert roundingMode >= ROUND_HALF_UP && + roundingMode <= ROUND_HALF_EVEN: "Unexpected rounding mode" + RoundingMode.valueOf(roundingMode); + + if (cmpFracHalf < 0 ) // We're closer to higher digit return false; - else if (roundingMode == ROUND_HALF_UP || - cmpFracHalf > 0 ) // We're closer to lower digit + else if (cmpFracHalf > 0 ) // We're closer to lower digit return true; - else - // roundingMode == ROUND_HALF_EVEN, true iff quotient is odd - return oddQuot; + else { // half-way + assert cmpFracHalf == 0; + + switch(roundingMode) { + case ROUND_HALF_DOWN: + return false; + + case ROUND_HALF_UP: + return true; + + case ROUND_HALF_EVEN: + return oddQuot; + + default: + throw new AssertionError("Unexpected rounding mode" + roundingMode); + } + } } }
07-09-2011

PUBLIC COMMENTS See http://hg.openjdk.java.net/jdk8/tl/jdk/rev/43880d125b79
07-09-2011

EVALUATION Yes.
04-09-2011