提交 b727cbea 编写于 作者: B bpb

8022180: BigInteger Burnikel-Ziegler quotient and remainder calculation...

8022180: BigInteger Burnikel-Ziegler quotient and remainder calculation assumes quotient parameter is zero
Summary: Clear the quotient in divideAndRemainderBurnikelZiegler() if the divisor is larger than the dividend.
Reviewed-by: alanb, bpb
Contributed-by: NTimothy Buktu <tbuktu@hotmail.com>
上级 b4ef2b1d
...@@ -1242,6 +1242,9 @@ class MutableBigInteger { ...@@ -1242,6 +1242,9 @@ class MutableBigInteger {
int r = intLen; int r = intLen;
int s = b.intLen; int s = b.intLen;
// Clear the quotient
quotient.offset = quotient.intLen = 0;
if (r < s) { if (r < s) {
return this; return this;
} else { } else {
...@@ -1276,7 +1279,6 @@ class MutableBigInteger { ...@@ -1276,7 +1279,6 @@ class MutableBigInteger {
// do schoolbook division on blocks, dividing 2-block numbers by 1-block numbers // do schoolbook division on blocks, dividing 2-block numbers by 1-block numbers
MutableBigInteger qi = new MutableBigInteger(); MutableBigInteger qi = new MutableBigInteger();
MutableBigInteger ri; MutableBigInteger ri;
quotient.offset = quotient.intLen = 0;
for (int i=t-2; i > 0; i--) { for (int i=t-2; i > 0; i--) {
// step 8a: compute (qi,ri) such that z=b*qi+ri // step 8a: compute (qi,ri) such that z=b*qi+ri
ri = z.divide2n1n(bShifted, qi); ri = z.divide2n1n(bShifted, qi);
......
...@@ -74,10 +74,10 @@ public class BigIntegerTest { ...@@ -74,10 +74,10 @@ public class BigIntegerTest {
static final int ORDER_SMALL = 60; static final int ORDER_SMALL = 60;
static final int ORDER_MEDIUM = 100; static final int ORDER_MEDIUM = 100;
// #bits for testing Karatsuba and Burnikel-Ziegler // #bits for testing Karatsuba
static final int ORDER_KARATSUBA = 1800; static final int ORDER_KARATSUBA = 1800;
// #bits for testing Toom-Cook // #bits for testing Toom-Cook and Burnikel-Ziegler
static final int ORDER_TOOM_COOK = 3000; static final int ORDER_TOOM_COOK = 4000;
// #bits for testing Karatsuba squaring // #bits for testing Karatsuba squaring
static final int ORDER_KARATSUBA_SQUARE = 3200; static final int ORDER_KARATSUBA_SQUARE = 3200;
// #bits for testing Toom-Cook squaring // #bits for testing Toom-Cook squaring
...@@ -964,12 +964,12 @@ public class BigIntegerTest { ...@@ -964,12 +964,12 @@ public class BigIntegerTest {
nextProbablePrime(); nextProbablePrime();
arithmetic(order1); // small numbers arithmetic(order1); // small numbers
arithmetic(order3); // Karatsuba / Burnikel-Ziegler range arithmetic(order3); // Karatsuba range
arithmetic(order4); // Toom-Cook range arithmetic(order4); // Toom-Cook / Burnikel-Ziegler range
divideAndRemainder(order1); // small numbers divideAndRemainder(order1); // small numbers
divideAndRemainder(order3); // Karatsuba / Burnikel-Ziegler range divideAndRemainder(order3); // Karatsuba range
divideAndRemainder(order4); // Toom-Cook range divideAndRemainder(order4); // Toom-Cook / Burnikel-Ziegler range
pow(order1); pow(order1);
pow(order3); pow(order3);
...@@ -989,8 +989,8 @@ public class BigIntegerTest { ...@@ -989,8 +989,8 @@ public class BigIntegerTest {
byteArrayConv(order1); byteArrayConv(order1);
modInv(order1); // small numbers modInv(order1); // small numbers
modInv(order3); // Karatsuba / Burnikel-Ziegler range modInv(order3); // Karatsuba range
modInv(order4); // Toom-Cook range modInv(order4); // Toom-Cook / Burnikel-Ziegler range
modExp(order1, order2); modExp(order1, order2);
modExp2(order1); modExp2(order1);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册