Commit 4c24ac27 by Raif S. Naffah Committed by Tom Tromey

BigInteger.java (euclidInv): Take result array as an argument.

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.

From-SVN: r63170
parent 3a24c513
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.
2003-02-20 Alexandre Oliva <aoliva@redhat.com> 2003-02-20 Alexandre Oliva <aoliva@redhat.com>
* configure.in: Propagate ORIGINAL_LD_FOR_MULTILIBS to * configure.in: Propagate ORIGINAL_LD_FOR_MULTILIBS to
......
...@@ -1017,8 +1017,8 @@ public class BigInteger extends Number implements Comparable ...@@ -1017,8 +1017,8 @@ public class BigInteger extends Number implements Comparable
return xy; return xy;
} }
private static final BigInteger[] euclidInv(BigInteger a, BigInteger b, private static final void euclidInv(BigInteger a, BigInteger b,
BigInteger prevDiv) BigInteger prevDiv, BigInteger[] xy)
{ {
if (b.isZero()) if (b.isZero())
throw new ArithmeticException("not invertible"); throw new ArithmeticException("not invertible");
...@@ -1027,20 +1027,19 @@ public class BigInteger extends Number implements Comparable ...@@ -1027,20 +1027,19 @@ public class BigInteger extends Number implements Comparable
{ {
// Success: values are indeed invertible! // Success: values are indeed invertible!
// Bottom of the recursion reached; start unwinding. // 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! // Recursion happens in the following conditional!
// If a just contains an int, then use integer math for the rest. // If a just contains an int, then use integer math for the rest.
if (a.words == null) if (a.words == null)
{ {
int[] xyInt = euclidInv(b.ival, a.ival % b.ival, a.ival / b.ival); int[] xyInt = euclidInv(b.ival, a.ival % b.ival, a.ival / b.ival);
result = new BigInteger[] { // non-shared BI xy[0] = new BigInteger(xyInt[0]);
new BigInteger(xyInt[0]), xy[1] = new BigInteger(xyInt[1]);
new BigInteger(xyInt[1])
};
} }
else else
{ {
...@@ -1050,13 +1049,12 @@ public class BigInteger extends Number implements Comparable ...@@ -1050,13 +1049,12 @@ public class BigInteger extends Number implements Comparable
// quot and rem may not be in canonical form. ensure // quot and rem may not be in canonical form. ensure
rem.canonicalize(); rem.canonicalize();
quot.canonicalize(); quot.canonicalize();
result = euclidInv(b, rem, quot); euclidInv(b, rem, quot, xy);
} }
BigInteger t = result[0]; BigInteger t = xy[0];
result[0] = add(result[1], times(t, prevDiv), -1); xy[0] = add(xy[1], times(t, prevDiv), -1);
result[1] = t; xy[1] = t;
return result;
} }
public BigInteger modInverse(BigInteger y) public BigInteger modInverse(BigInteger y)
...@@ -1124,9 +1122,8 @@ public class BigInteger extends Number implements Comparable ...@@ -1124,9 +1122,8 @@ public class BigInteger extends Number implements Comparable
// quot and rem may not be in canonical form. ensure // quot and rem may not be in canonical form. ensure
rem.canonicalize(); rem.canonicalize();
quot.canonicalize(); quot.canonicalize();
BigInteger xy0 = new BigInteger(); BigInteger[] xy = new BigInteger[2];
BigInteger xy1 = new BigInteger(); euclidInv(y, rem, quot, xy);
BigInteger[] xy = euclidInv(y, rem, quot);
result = swapped ? xy[0] : xy[1]; result = swapped ? xy[0] : xy[1];
// Result can't be negative, so make it positive by adding the // Result can't be negative, so make it positive by adding the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment