libgcj/1615
Per Bothner
per@bothner.com
Sun Apr 1 00:00:00 GMT 2001
The following reply was made to PR libgcj/1615; it has been noted by GNATS.
From: Per Bothner <per@bothner.com>
To: gcc-gnats@gcc.gnu.org, mjr@statesmean.com, warrenl@gcc.gnu.org
Cc: per@bothner.com
Subject: Re: libgcj/1615
Date: 11 Feb 2001 15:36:59 -0800
I took a look at the code for BigInteger.modPow, and noticed something
rather suspicious: The variable s is never used. Perhaps
double-checking the referenced algorithm would make sense.
Another problem: if exponent.isNegative() then modInverse(m) is
called. That seems unlikely to be correct if exponent < -1.
One trivial performance improvement that should be done: Replace
u.and(ONE).isOne() by u.isOdd(). Even better would be to drop u
entirely, and just use bitValue(exponent, i) (where i starts at 0 is
is increment on each iteration), where:
/** Return the value of a specified bit in an BigInteger. */
public static boolean bitValue (BigInteger x, int bitno)
{
int i = x.ival;
if (x.words == null)
{
return bitno >= 32 ? i < 0 : ((i >> bitno) & 1) != 0;
}
else
{
int wordno = bitno >> 5;
return wordno >= i ? x.words[i-1] < 0
: (((x.words[wordno]) >> bitno) & 1) != 0;
}
}
/* This is cut-and-pasted from Kawa, so may need soem tweaking. */
--
--Per Bothner
per@bothner.com http://www.bothner.com/~per/
More information about the Gcc-prs
mailing list