6850606: Regression from JDK 1.6.0_12
authorxlu
Sat, 20 Jun 2009 13:34:06 -0700
changeset 3053 a42e2cc2aaa5
parent 3052 5c9886498f31
child 3054 ddb6acba8b6f
6850606: Regression from JDK 1.6.0_12 Summary: The returned result from multiply should be constructed by using valueOf to take care of the INFLATED case. Reviewed-by: darcy
jdk/src/share/classes/java/math/BigDecimal.java
jdk/test/java/math/BigDecimal/MultiplyTests.java
--- a/jdk/src/share/classes/java/math/BigDecimal.java	Fri Jun 19 14:39:06 2009 -0700
+++ b/jdk/src/share/classes/java/math/BigDecimal.java	Sat Jun 20 13:34:06 2009 -0700
@@ -1101,7 +1101,7 @@
             // See "Hacker's Delight" section 2-12 for explanation of
             // the overflow test.
             if ( (((sum ^ xs) & (sum ^ ys))) >= 0L) // not overflowed
-                return new BigDecimal(null, sum, rscale, 0);
+                return BigDecimal.valueOf(sum, rscale);
         }
         if (fst == null)
             fst = BigInteger.valueOf(xs);
@@ -1311,9 +1311,9 @@
              * would occur since division is expensive on most CPUs.
              */
             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)))
-                return new BigDecimal(null, product, productScale, 0);
+                return BigDecimal.valueOf(product, productScale);
             return new BigDecimal(BigInteger.valueOf(x).multiply(y), INFLATED,
                                   productScale, 0);
         }
@@ -1584,7 +1584,7 @@
             return (preferredScale >= 0 &&
                     preferredScale < ZERO_SCALED_BY.length) ?
                 ZERO_SCALED_BY[preferredScale] :
-                new BigDecimal(null, 0, preferredScale, 1);
+                BigDecimal.valueOf(0, preferredScale);
         else {
             this.inflate();
             divisor.inflate();
--- a/jdk/test/java/math/BigDecimal/MultiplyTests.java	Fri Jun 19 14:39:06 2009 -0700
+++ b/jdk/test/java/math/BigDecimal/MultiplyTests.java	Sat Jun 20 13:34:06 2009 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 1234567
+ * @bug 6850606
  * @summary Test BigDecimal.multiply(BigDecimal)
  * @author xlu
  */
@@ -72,6 +72,16 @@
                 }
             }
         }
+
+        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;
     }