6850606: Regression from JDK 1.6.0_12
The returned result from multiply should be constructed by using valueOf to take care of the INFLATED case. Reviewed-by: darcy
This commit is contained in:
parent
721a90bda5
commit
c0146a5bd0
@ -1101,7 +1101,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
|
|||||||
// See "Hacker's Delight" section 2-12 for explanation of
|
// See "Hacker's Delight" section 2-12 for explanation of
|
||||||
// the overflow test.
|
// the overflow test.
|
||||||
if ( (((sum ^ xs) & (sum ^ ys))) >= 0L) // not overflowed
|
if ( (((sum ^ xs) & (sum ^ ys))) >= 0L) // not overflowed
|
||||||
return new BigDecimal(null, sum, rscale, 0);
|
return BigDecimal.valueOf(sum, rscale);
|
||||||
}
|
}
|
||||||
if (fst == null)
|
if (fst == null)
|
||||||
fst = BigInteger.valueOf(xs);
|
fst = BigInteger.valueOf(xs);
|
||||||
@ -1311,9 +1311,9 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
|
|||||||
* would occur since division is expensive on most CPUs.
|
* would occur since division is expensive on most CPUs.
|
||||||
*/
|
*/
|
||||||
long product = x * y;
|
long product = x * y;
|
||||||
int prec = this.precision() + multiplicand.precision();
|
long prec = this.precision() + multiplicand.precision();
|
||||||
if (prec < 19 || (prec < 21 && (y == 0 || product / y == x)))
|
if (prec < 19 || (prec < 21 && (y == 0 || product / y == x)))
|
||||||
return new BigDecimal(null, product, productScale, 0);
|
return BigDecimal.valueOf(product, productScale);
|
||||||
return new BigDecimal(BigInteger.valueOf(x).multiply(y), INFLATED,
|
return new BigDecimal(BigInteger.valueOf(x).multiply(y), INFLATED,
|
||||||
productScale, 0);
|
productScale, 0);
|
||||||
}
|
}
|
||||||
@ -1584,7 +1584,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
|
|||||||
return (preferredScale >= 0 &&
|
return (preferredScale >= 0 &&
|
||||||
preferredScale < ZERO_SCALED_BY.length) ?
|
preferredScale < ZERO_SCALED_BY.length) ?
|
||||||
ZERO_SCALED_BY[preferredScale] :
|
ZERO_SCALED_BY[preferredScale] :
|
||||||
new BigDecimal(null, 0, preferredScale, 1);
|
BigDecimal.valueOf(0, preferredScale);
|
||||||
else {
|
else {
|
||||||
this.inflate();
|
this.inflate();
|
||||||
divisor.inflate();
|
divisor.inflate();
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 1234567
|
* @bug 6850606
|
||||||
* @summary Test BigDecimal.multiply(BigDecimal)
|
* @summary Test BigDecimal.multiply(BigDecimal)
|
||||||
* @author xlu
|
* @author xlu
|
||||||
*/
|
*/
|
||||||
@ -72,6 +72,16 @@ public class MultiplyTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BigDecimal x = BigDecimal.valueOf(8L, 1);
|
||||||
|
BigDecimal xPower = BigDecimal.valueOf(-1L);
|
||||||
|
try {
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
|
xPower = xPower.multiply(x);
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
failures++;
|
||||||
|
}
|
||||||
return failures;
|
return failures;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user