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. From-SVN: r40177
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 1999, 2000 Free Software Foundation
|
||||
/* Copyright (C) 1999, 2000, 2001 Free Software Foundation
|
||||
|
||||
This file is part of libgcj.
|
||||
|
||||
@@ -481,7 +481,7 @@ public class MPN
|
||||
return xlen > ylen ? 1 : xlen < ylen ? -1 : cmp (x, y, xlen);
|
||||
}
|
||||
|
||||
/* Shift x[x_start:x_start+len-1]count bits to the "right"
|
||||
/* Shift x[x_start:x_start+len-1] count bits to the "right"
|
||||
* (i.e. divide by 2**count).
|
||||
* Store the len least significant words of the result at dest.
|
||||
* The bits shifted out to the right are returned.
|
||||
@@ -506,6 +506,23 @@ public class MPN
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* Shift x[x_start:x_start+len-1] count bits to the "right"
|
||||
* (i.e. divide by 2**count).
|
||||
* Store the len least significant words of the result at dest.
|
||||
* OK if dest==x.
|
||||
* Assumes: 0 <= count < 32
|
||||
* Same as rshift, but handles count==0 (and has no return value).
|
||||
*/
|
||||
public static void rshift0 (int[] dest, int[] x, int x_start,
|
||||
int len, int count)
|
||||
{
|
||||
if (count > 0)
|
||||
rshift(dest, x, x_start, len, count);
|
||||
else
|
||||
for (int i = 0; i < len; i++)
|
||||
dest[i] = x[i + x_start];
|
||||
}
|
||||
|
||||
/** Return the long-truncated value of right shifting.
|
||||
* @param x a two's-complement "bignum"
|
||||
* @param len the number of significant words in x
|
||||
@@ -530,20 +547,6 @@ public class MPN
|
||||
return ((long)w1 << 32) | ((long)w0 & 0xffffffffL);
|
||||
}
|
||||
|
||||
/* Shift x[0:len-1]count bits to the "right" (i.e. divide by 2**count).
|
||||
* Store the len least significant words of the result at dest.
|
||||
* OK if dest==x.
|
||||
* OK if count > 32 (but must be >= 0).
|
||||
*/
|
||||
public static void rshift (int[] dest, int[] x, int len, int count)
|
||||
{
|
||||
int word_count = count >> 5;
|
||||
count &= 31;
|
||||
rshift (dest, x, word_count, len, count);
|
||||
while (word_count < len)
|
||||
dest[word_count++] = 0;
|
||||
}
|
||||
|
||||
/* Shift x[0:len-1] left by count bits, and store the len least
|
||||
* significant words of the result in dest[d_offset:d_offset+len-1].
|
||||
* Return the bits shifted out from the most significant digit.
|
||||
@@ -624,8 +627,8 @@ public class MPN
|
||||
|
||||
// Temporarily devide both x and y by 2**sh.
|
||||
len -= initShiftWords;
|
||||
MPN.rshift (x, x, initShiftWords, len, initShiftBits);
|
||||
MPN.rshift (y, y, initShiftWords, len, initShiftBits);
|
||||
MPN.rshift0 (x, x, initShiftWords, len, initShiftBits);
|
||||
MPN.rshift0 (y, y, initShiftWords, len, initShiftBits);
|
||||
|
||||
int[] odd_arg; /* One of x or y which is odd. */
|
||||
int[] other_arg; /* The other one can be even or odd. */
|
||||
@@ -704,7 +707,7 @@ public class MPN
|
||||
}
|
||||
|
||||
/** Calcaulte the Common Lisp "integer-length" function.
|
||||
* Assumes input is canonicalized: len==IntNum.wordsNeeded(words,len) */
|
||||
* Assumes input is canonicalized: len==BigInteger.wordsNeeded(words,len) */
|
||||
public static int intLength (int[] words, int len)
|
||||
{
|
||||
len--;
|
||||
@@ -712,7 +715,7 @@ public class MPN
|
||||
}
|
||||
|
||||
/* DEBUGGING:
|
||||
public static void dprint (IntNum x)
|
||||
public static void dprint (BigInteger x)
|
||||
{
|
||||
if (x.words == null)
|
||||
System.err.print(Long.toString((long) x.ival & 0xffffffffL, 16));
|
||||
|
||||
Reference in New Issue
Block a user