diff --git a/src/share/classes/java/math/MutableBigInteger.java b/src/share/classes/java/math/MutableBigInteger.java index 804d8be8e7aa956e6c304ef7e6eb833ad7bf90a7..6f72f2d0c83589e583e57df64568bd296dcd75cc 100644 --- a/src/share/classes/java/math/MutableBigInteger.java +++ b/src/share/classes/java/math/MutableBigInteger.java @@ -1242,6 +1242,9 @@ class MutableBigInteger { int r = intLen; int s = b.intLen; + // Clear the quotient + quotient.offset = quotient.intLen = 0; + if (r < s) { return this; } else { @@ -1276,7 +1279,6 @@ class MutableBigInteger { // do schoolbook division on blocks, dividing 2-block numbers by 1-block numbers MutableBigInteger qi = new MutableBigInteger(); MutableBigInteger ri; - quotient.offset = quotient.intLen = 0; for (int i=t-2; i > 0; i--) { // step 8a: compute (qi,ri) such that z=b*qi+ri ri = z.divide2n1n(bShifted, qi); diff --git a/test/java/math/BigInteger/BigIntegerTest.java b/test/java/math/BigInteger/BigIntegerTest.java index 47f6af56c2ef7f507785c4753a8d7942140e1834..279f5546b58523254c6a4d3c393058c6a12c5a71 100644 --- a/test/java/math/BigInteger/BigIntegerTest.java +++ b/test/java/math/BigInteger/BigIntegerTest.java @@ -74,10 +74,10 @@ public class BigIntegerTest { static final int ORDER_SMALL = 60; static final int ORDER_MEDIUM = 100; - // #bits for testing Karatsuba and Burnikel-Ziegler + // #bits for testing Karatsuba static final int ORDER_KARATSUBA = 1800; - // #bits for testing Toom-Cook - static final int ORDER_TOOM_COOK = 3000; + // #bits for testing Toom-Cook and Burnikel-Ziegler + static final int ORDER_TOOM_COOK = 4000; // #bits for testing Karatsuba squaring static final int ORDER_KARATSUBA_SQUARE = 3200; // #bits for testing Toom-Cook squaring @@ -964,12 +964,12 @@ public class BigIntegerTest { nextProbablePrime(); arithmetic(order1); // small numbers - arithmetic(order3); // Karatsuba / Burnikel-Ziegler range - arithmetic(order4); // Toom-Cook range + arithmetic(order3); // Karatsuba range + arithmetic(order4); // Toom-Cook / Burnikel-Ziegler range divideAndRemainder(order1); // small numbers - divideAndRemainder(order3); // Karatsuba / Burnikel-Ziegler range - divideAndRemainder(order4); // Toom-Cook range + divideAndRemainder(order3); // Karatsuba range + divideAndRemainder(order4); // Toom-Cook / Burnikel-Ziegler range pow(order1); pow(order3); @@ -989,8 +989,8 @@ public class BigIntegerTest { byteArrayConv(order1); modInv(order1); // small numbers - modInv(order3); // Karatsuba / Burnikel-Ziegler range - modInv(order4); // Toom-Cook range + modInv(order3); // Karatsuba range + modInv(order4); // Toom-Cook / Burnikel-Ziegler range modExp(order1, order2); modExp2(order1);