summaryrefslogtreecommitdiff
path: root/libjava
diff options
context:
space:
mode:
authortromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2003-02-17 23:18:39 +0000
committertromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2003-02-17 23:18:39 +0000
commitd49fc383f10a91295c484e9d34f7710d0df40a5d (patch)
treeed14f9d46bd2f90bac0eac6fbcba29d95eebb8fe /libjava
parentaab4c0159f63aa6e2b4232b6b0986aa0971a129d (diff)
downloadgcc-d49fc383f10a91295c484e9d34f7710d0df40a5d.tar.gz
2003-02-17 Raif S. Naffah <raif@fl.net.au>
* java/math/BigInteger.java (euclidInv): Return array of `BigInteger's. Changed all callers. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@63014 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava')
-rw-r--r--libjava/ChangeLog5
-rw-r--r--libjava/java/math/BigInteger.java33
2 files changed, 20 insertions, 18 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index e417849ee5a..c8c62cbbb35 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,8 @@
+2003-02-17 Raif S. Naffah <raif@fl.net.au>
+
+ * java/math/BigInteger.java (euclidInv): Return array of
+ `BigInteger's. Changed all callers.
+
2003-02-17 Ranjit Mathew <rmathew@hotmail.com>
* java/util/Properties.java (store): Move the code formerly in
diff --git a/libjava/java/math/BigInteger.java b/libjava/java/math/BigInteger.java
index f7242904671..6a17cf3b75c 100644
--- a/libjava/java/math/BigInteger.java
+++ b/libjava/java/math/BigInteger.java
@@ -1017,9 +1017,8 @@ public class BigInteger extends Number implements Comparable
return xy;
}
- private static final void euclidInv(BigInteger a, BigInteger b,
- BigInteger prevDiv, BigInteger xy0,
- BigInteger xy1, BigInteger xy2)
+ private static final BigInteger[] euclidInv(BigInteger a, BigInteger b,
+ BigInteger prevDiv)
{
if (b.isZero())
throw new ArithmeticException("not invertible");
@@ -1028,20 +1027,20 @@ public class BigInteger extends Number implements Comparable
{
// Success: values are indeed invertible!
// Bottom of the recursion reached; start unwinding.
- // WARNING: xy1 is, and xy0 may be, a shared BI!
- xy0 = neg(prevDiv);
- xy1 = ONE;
- return;
+ return new BigInteger[] { neg(prevDiv), ONE };
}
+ BigInteger[] result;
// Recursion happens in the following conditional!
// If a just contains an int, then use integer math for the rest.
if (a.words == null)
{
int[] xyInt = euclidInv(b.ival, a.ival % b.ival, a.ival / b.ival);
- xy0 = new BigInteger(xyInt[0]); // non-shared BI
- xy1 = new BigInteger(xyInt[1]); // non-shared BI
+ result = new BigInteger[] { // non-shared BI
+ new BigInteger(xyInt[0]),
+ new BigInteger(xyInt[1])
+ };
}
else
{
@@ -1051,15 +1050,13 @@ public class BigInteger extends Number implements Comparable
// quot and rem may not be in canonical form. ensure
rem.canonicalize();
quot.canonicalize();
- euclidInv(b, rem, quot, xy0, xy1, xy2);
+ result = euclidInv(b, rem, quot);
}
- // xy2 is just temp storage for intermediate results in the following
- // calculation. This saves us a bit of space over having a BigInteger
- // allocated at every level of this recursive method.
- xy2 = xy0;
- xy0 = add(xy1, times(xy2, prevDiv), -1);
- xy1 = xy2;
+ BigInteger t = result[0];
+ result[0] = add(result[1], times(t, prevDiv), -1);
+ result[1] = t;
+ return result;
}
public BigInteger modInverse(BigInteger y)
@@ -1129,8 +1126,8 @@ public class BigInteger extends Number implements Comparable
quot.canonicalize();
BigInteger xy0 = new BigInteger();
BigInteger xy1 = new BigInteger();
- euclidInv(y, rem, quot, xy0, xy1, result);
- result = swapped ? xy0 : xy1;
+ BigInteger[] xy = euclidInv(y, rem, quot);
+ result = swapped ? xy[0] : xy[1];
// Result can't be negative, so make it positive by adding the
// original modulus, y (which is now x if they were swapped).