This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: BigInteger.modInverse() fix
-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160
On Monday 16 December 2002 20:04, Per Bothner wrote:
> ...The method canonicalize does three things:
> (1) Figure out the minimum number of words needs, and set ival to
> that. (2) If the number of words needed is <= 1,
> drop the words array, replacing ival by words[0].
> (3) If the valus is in the range [minFixNum, maxFixNum]
> return this, otherwise return an equivalent element in smallFixInts.
>
> Doing (1) and (2) may be needed for correctness.
> Doing (2) is desirable for speed and space (dropping the words
> array). It might affect correctness, but only because some methods
> (such as equals) assume their arguments are canonicalized.
> Doing (3) is to reduce the number of objects that allocated (since
> most integers will be small integers). It does not effect which
> algorithms are chosen.
>
> The difference between:
> rem = rem.canonicalize();
> and
> rem.canonicalize();
> is whether steps (1-3) are done or whether only steps (1-2) are
> done. Steps (1) and (2) are done either way. Whether (3) is
> done will *not* effect which algorithms are used.
the safest ways to solve the bug that i can see are:
1. the patch as submitted,
2. refactor the canonicalize() method to separate the code for steps 1
and 2, say a toShortForm() method, from the rest. toShortForm() would
then get called by canonicalize() and used in the patch.
using rem = rem.canonicalize() may be ok, but one has to go through the
code, thouroughly, and ensure that no "destructive" method (one that
changes the .ival and .words attributes of the BigInteger instance) is
called on a smallFixNums instance. this is not trivial.
cheers;
rsn
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
Comment: Que du magnifique
iD8DBQE9/t4O+e1AKnsTRiERA7D0AJ9puej2UWkUU8AqdjVXUyZBTyVRUwCaAxGg
ybB15TkddjZOmjo+xJi5nDs=
=EehT
-----END PGP SIGNATURE-----