Details
-
Bug
-
Resolution: Fixed
-
P2
-
6u10
-
b72
-
sparc
-
solaris_10
-
Verified
Backports
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2182404 | 6u18 | Xiaobin Lu | P2 | Closed | Fixed | b02 |
JDK-2202266 | OpenJDK6 | Joe Darcy | P4 | Resolved | Fixed | b21 |
Description
Occurs on JRE 6 updates 14 and 16. It does not occur for 13 or 05. Also doesn't occur for JRE 5. JDK doesnt seem to matter.
ADDITIONAL OS VERSION INFORMATION :
SunOS noc5pbbatchdev2z1 5.10 Generic_137137-09 sun4u sparc SUNW,Sun-Fire-V490
Microsoft Windows XP [Version 5.1.2600]
(Found error on both.)
A DESCRIPTION OF THE PROBLEM :
Doing regression testing with switch from java 5 to java 6 we came across a discrepancy between bigdecimal results of divide. Based on the javadocs, the three divide method invocations below should correctly round the result up to 0.000115309916. However, they are not doing that. They are either rounding down or truncating or otherwise messing up, and are always giving a 5 as the last digit, rather than a 6. Further investigation determined that this was an issue with JRE 6u14 and u16, but did not occur with JRE6u13 or u05, and jdk doesnt seem to matter.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Get JRE 6u14, or u16. (Good chance everything u14+ will have the bug in it.) Use JDK 6u16 (although i dont believe jdk matters.) Then run the code below.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
div1: 0.000115309915
div2: 0.000115309915
div3: 0.000115309915
ACTUAL -
div1: 0.000115309916
div2: 0.000115309916
div3: 0.000115309916
REPRODUCIBILITY :
This bug can be reproduced rarely.
---------- BEGIN SOURCE ----------
import java.math.*;
public class yy
{
public static void main(String[] args)
{
try {
BigDecimal one = new BigDecimal("962.430000000000");
BigDecimal two = new BigDecimal("8346463.460000000000");
BigDecimal div1 = one.divide(two, 12, RoundingMode.HALF_UP);
BigDecimal div2 = one.divide(two, RoundingMode.HALF_UP);
BigDecimal div3 = one.divide(two, new MathContext(9));
System.out.println("div1: " + div1);
System.out.println("div2: " + div2);
System.out.println("div3: " + div3);
} catch (Exception E) {
E.printStackTrace();
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
None found yet.
Attachments
Issue Links
- backported by
-
JDK-2202266 BigDecimal's divide(BigDecimal bd, RoundingFormat r) produces incorrect result
- Resolved
-
JDK-2182404 BigDecimal's divide(BigDecimal bd, RoundingFormat r) produces incorrect result
- Closed
- relates to
-
JDK-6812880 AssertionError in BigDecimal.remainder
- Resolved
-
JDK-6837951 Incorrect answer while summing serialized / deserialized BigDecimals
- Resolved
-
JDK-6819773 BigDecimal.divide(BigDecimal,int,int) throws ArrayIndexOutofBoundsException under some circumstances
- Resolved
-
JDK-6850606 Regression from JDK 1.6.0_12
- Closed
-
JDK-6622432 RFE: Performance improvements to java.math.BigDecimal
- Resolved
-
JDK-6806261 BigDecimal.longValueExact() method throws NullPointerException
- Resolved
-
JDK-8066842 java.math.BigDecimal.divide(BigDecimal, RoundingMode) produces incorrect result
- Closed