test/java/math/BigDecimal/IntegralDivisionTests.java
Print this page
rev 7924 : 6378503: In java.math.BigDecimal, division by one returns zero
6446965: Using BigDecimal.divideToIntegralValue with extreme scales can lead to an incorrect result
Summary: Fix overflow of ints and ensure appropriate values passed to checkScaleNonZero()
Reviewed-by: darcy, martin
Contributed-by: Brian Burkhalter <brian.burkhalter@oracle.com>
@@ -20,11 +20,11 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
- * @bug 4904082 4917089 6337226
+ * @bug 4904082 4917089 6337226 6378503
* @summary Tests that integral division and related methods return the proper result and scale.
* @author Joseph D. Darcy
*/
import java.math.*;
public class IntegralDivisionTests {
@@ -45,10 +45,13 @@
{new BigDecimal("1e9"), new BigDecimal("0.1"), new BigDecimal("1e10")},
{new BigDecimal("10e8"), new BigDecimal("0.1"), new BigDecimal("10e9")},
{new BigDecimal("400e1"), new BigDecimal("5"), new BigDecimal("80e1")},
{new BigDecimal("400e1"), new BigDecimal("4.999999999"), new BigDecimal("8e2")},
{new BigDecimal("40e2"), new BigDecimal("5"), new BigDecimal("8e2")},
+ {BigDecimal.valueOf(1, Integer.MIN_VALUE),
+ BigDecimal.valueOf(1, -(Integer.MAX_VALUE & 0x7fffff00)),
+ BigDecimal.valueOf(1, -256)},
};
for(BigDecimal [] testCase: moreTestCases) {
BigDecimal quotient;
if (! (quotient=testCase[0].divideToIntegralValue(testCase[1])).equals(testCase[2]) ){