summaryrefslogtreecommitdiff
path: root/libjava/java/math
diff options
context:
space:
mode:
authortromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2003-02-20 16:55:15 +0000
committertromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2003-02-20 16:55:15 +0000
commite9a4e72a8b45cbdc9fbd4b5cbee37c0e8e8a3404 (patch)
treeea5acbe8c41e9f0300a9d814fb213636e34ce8a1 /libjava/java/math
parent5efd14f18b42a74b5dcb1b2b5ce64c618d1bcfab (diff)
downloadgcc-e9a4e72a8b45cbdc9fbd4b5cbee37c0e8e8a3404.tar.gz
2003-02-20 Raif S. Naffah <raif@fl.net.au>
* java/math/BigInteger.java (euclidInv): Take result array as an argument. Updated all callers. (modInverse): Removed unused variables. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@63170 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java/math')
-rw-r--r--libjava/java/math/BigInteger.java29
1 files changed, 13 insertions, 16 deletions
diff --git a/libjava/java/math/BigInteger.java b/libjava/java/math/BigInteger.java
index 6a17cf3b75c..6f919f785cc 100644
--- a/libjava/java/math/BigInteger.java
+++ b/libjava/java/math/BigInteger.java
@@ -1017,8 +1017,8 @@ public class BigInteger extends Number implements Comparable
return xy;
}
- private static final BigInteger[] euclidInv(BigInteger a, BigInteger b,
- BigInteger prevDiv)
+ private static final void euclidInv(BigInteger a, BigInteger b,
+ BigInteger prevDiv, BigInteger[] xy)
{
if (b.isZero())
throw new ArithmeticException("not invertible");
@@ -1027,20 +1027,19 @@ public class BigInteger extends Number implements Comparable
{
// Success: values are indeed invertible!
// Bottom of the recursion reached; start unwinding.
- return new BigInteger[] { neg(prevDiv), ONE };
+ xy[0] = neg(prevDiv);
+ xy[1] = ONE;
+ return;
}
- 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);
- result = new BigInteger[] { // non-shared BI
- new BigInteger(xyInt[0]),
- new BigInteger(xyInt[1])
- };
+ xy[0] = new BigInteger(xyInt[0]);
+ xy[1] = new BigInteger(xyInt[1]);
}
else
{
@@ -1050,13 +1049,12 @@ public class BigInteger extends Number implements Comparable
// quot and rem may not be in canonical form. ensure
rem.canonicalize();
quot.canonicalize();
- result = euclidInv(b, rem, quot);
+ euclidInv(b, rem, quot, xy);
}
- BigInteger t = result[0];
- result[0] = add(result[1], times(t, prevDiv), -1);
- result[1] = t;
- return result;
+ BigInteger t = xy[0];
+ xy[0] = add(xy[1], times(t, prevDiv), -1);
+ xy[1] = t;
}
public BigInteger modInverse(BigInteger y)
@@ -1124,9 +1122,8 @@ public class BigInteger extends Number implements Comparable
// quot and rem may not be in canonical form. ensure
rem.canonicalize();
quot.canonicalize();
- BigInteger xy0 = new BigInteger();
- BigInteger xy1 = new BigInteger();
- BigInteger[] xy = euclidInv(y, rem, quot);
+ BigInteger[] xy = new BigInteger[2];
+ euclidInv(y, rem, quot, xy);
result = swapped ? xy[0] : xy[1];
// Result can't be negative, so make it positive by adding the