Commit 552cc5b5 by Warren Levy Committed by Warren Levy

BigInteger.java (divide): Handle the special case when dividing by 1 and the…

BigInteger.java (divide): Handle the special case when dividing by 1 and the high bit of the dividend is set.

	* java/math/BigInteger.java(divide): Handle the special case when
	dividing by 1 and the high bit of the dividend is set.
	(setShiftRight): Handle case when count == 0.

From-SVN: r32724
parent 111393df
2000-03-24 Warren Levy <warrenl@cygnus.com> 2000-03-24 Warren Levy <warrenl@cygnus.com>
* java/math/BigInteger.java(divide): Handle the special case when
dividing by 1 and the high bit of the dividend is set.
(setShiftRight): Handle case when count == 0.
2000-03-24 Warren Levy <warrenl@cygnus.com>
* java/awt/Font.java(isBold): Fix syntax error. * java/awt/Font.java(isBold): Fix syntax error.
(isItalic): ditto. (isItalic): ditto.
* java/awt/Frame.java(postEvent): ditto. * java/awt/Frame.java(postEvent): ditto.
......
...@@ -750,6 +750,12 @@ public class BigInteger extends Number implements Comparable ...@@ -750,6 +750,12 @@ public class BigInteger extends Number implements Comparable
else if (ylen == 1) else if (ylen == 1)
{ {
qlen = xlen; qlen = xlen;
// Need to leave room for a word of leading zeros if dividing by 1
// and the dividend has the high bit set. It might be safe to
// increment qlen in all cases, but it certainly is only necessary
// in the following case.
if (ywords[0] == 1 && xwords[xlen-1] < 0)
qlen++;
rlen = 1; rlen = 1;
ywords[0] = MPN.divmod_1(xwords, xwords, xlen, ywords[0]); ywords[0] = MPN.divmod_1(xwords, xwords, xlen, ywords[0]);
} }
...@@ -770,7 +776,7 @@ public class BigInteger extends Number implements Comparable ...@@ -770,7 +776,7 @@ public class BigInteger extends Number implements Comparable
// significant word. // significant word.
int x_high = MPN.lshift(xwords, 0, xwords, xlen, nshift); int x_high = MPN.lshift(xwords, 0, xwords, xlen, nshift);
xwords[xlen++] = x_high; xwords[xlen++] = x_high;
} }
if (xlen == ylen) if (xlen == ylen)
xwords[xlen++] = 0; xwords[xlen++] = 0;
...@@ -1381,7 +1387,10 @@ public class BigInteger extends Number implements Comparable ...@@ -1381,7 +1387,10 @@ public class BigInteger extends Number implements Comparable
{ {
if (words == null || words.length < d_len) if (words == null || words.length < d_len)
realloc(d_len); realloc(d_len);
MPN.rshift(words, x.words, word_count, d_len, count); if (count == 0)
System.arraycopy(x.words, word_count, words, 0, d_len);
else
MPN.rshift(words, x.words, word_count, d_len, count);
ival = d_len; ival = d_len;
if (neg) if (neg)
words[ival-1] |= -1 << (32 - count); words[ival-1] |= -1 << (32 - count);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment