From 4baba9f150e4013de41d1f05f567ff14d9af3db4 Mon Sep 17 00:00:00 2001 From: bothner Date: Fri, 2 Mar 2001 06:55:33 +0000 Subject: Changes merged from Kawa's gnu.math. * java/math/BigInteger.java * gnu/gcj/math/MPN.java (rshift0): New method handles zero shift count. (rshift(int[],int[],int,int): Removed - not needed. (gcd): Use rshift0 rather than rshift. * java/math/BigInteger.java (setShiftRight): Likewise. (divide): Simplify by using rshift0. (divide): Zero-extend results if high-order bit set. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@40177 138bc75d-0d04-0410-961f-82ee72b054a4 --- libjava/java/math/BigInteger.java | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'libjava/java') diff --git a/libjava/java/math/BigInteger.java b/libjava/java/math/BigInteger.java index 0d8608eecc3..1d848d13e8f 100644 --- a/libjava/java/math/BigInteger.java +++ b/libjava/java/math/BigInteger.java @@ -794,13 +794,7 @@ public class BigInteger extends Number implements Comparable xwords[xlen++] = 0; MPN.divide(xwords, xlen, ywords, ylen); rlen = ylen; - if (remainder != null || rounding_mode != TRUNCATE) - { - if (nshift == 0) - System.arraycopy(xwords, 0, ywords, 0, rlen); - else - MPN.rshift(ywords, xwords, 0, rlen, nshift); - } + MPN.rshift0 (ywords, xwords, 0, rlen, nshift); qlen = xlen + 1 - ylen; if (quotient != null) @@ -810,6 +804,12 @@ public class BigInteger extends Number implements Comparable } } + if (ywords[rlen-1] < 0) + { + ywords[rlen] = 0; + rlen++; + } + // Now the quotient is in xwords, and the remainder is in ywords. boolean add_one = false; @@ -1399,15 +1399,10 @@ public class BigInteger extends Number implements Comparable { if (words == null || words.length < d_len) realloc(d_len); - if (count == 0) - System.arraycopy(x.words, word_count, words, 0, d_len); - else - { - MPN.rshift(words, x.words, word_count, d_len, count); - if (neg) - words[d_len-1] |= -1 << (32 - count); - } + MPN.rshift0 (words, x.words, word_count, d_len, count); ival = d_len; + if (neg) + words[d_len-1] |= -1 << (32 - count); } } } -- cgit v1.2.3