summaryrefslogtreecommitdiffstats
path: root/libjava/java/math
diff options
context:
space:
mode:
authorwarrenl <warrenl@138bc75d-0d04-0410-961f-82ee72b054a4>2000-03-24 09:18:12 +0000
committerwarrenl <warrenl@138bc75d-0d04-0410-961f-82ee72b054a4>2000-03-24 09:18:12 +0000
commitb7abbf69a7d3f534f3606af794f2ee12fec75575 (patch)
tree81ac4785b8794f96ebc0913df70f460cf45208ec /libjava/java/math
parent16733ee3215a2c7e356342a07023aa3f185c5f89 (diff)
downloadppe42-gcc-b7abbf69a7d3f534f3606af794f2ee12fec75575.tar.gz
ppe42-gcc-b7abbf69a7d3f534f3606af794f2ee12fec75575.zip
* 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@32724 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java/math')
-rw-r--r--libjava/java/math/BigInteger.java13
1 files changed, 11 insertions, 2 deletions
diff --git a/libjava/java/math/BigInteger.java b/libjava/java/math/BigInteger.java
index 69e7f68506b..738680a42c4 100644
--- a/libjava/java/math/BigInteger.java
+++ b/libjava/java/math/BigInteger.java
@@ -750,6 +750,12 @@ public class BigInteger extends Number implements Comparable
else if (ylen == 1)
{
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;
ywords[0] = MPN.divmod_1(xwords, xwords, xlen, ywords[0]);
}
@@ -770,7 +776,7 @@ public class BigInteger extends Number implements Comparable
// significant word.
int x_high = MPN.lshift(xwords, 0, xwords, xlen, nshift);
xwords[xlen++] = x_high;
- }
+ }
if (xlen == ylen)
xwords[xlen++] = 0;
@@ -1381,7 +1387,10 @@ public class BigInteger extends Number implements Comparable
{
if (words == null || words.length < 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;
if (neg)
words[ival-1] |= -1 << (32 - count);
OpenPOWER on IntegriCloud