This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [freenet-devl] Re: Yet another GCJ update. (a/k/a PR 1615 followup)


"Mark J. Roberts" <mjr@statesmean.com> writes:

> This patch fixes a situation where BigInteger.divide generates bogus
> remainders and quotients for certain input. I posted a test case for this,
> you can see it at http://gcc.gnu.org/ml/java/2001-02/msg00293.html. This
> patch fixes that bug:

Well, the strange thing is that when I do the division in Kawa (using
gnu.math), I get the correct result. But while doing some experiments,
comparing the the gnu.math.IntNum and BigInteger source I noticed that
the latter was missing the following code:

Index: BigInteger.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/math/BigInteger.java,v
retrieving revision 1.10
diff -u -r1.10 BigInteger.java
--- BigInteger.java	2001/01/17 04:13:17	1.10
+++ BigInteger.java	2001/02/24 04:58:38
@@ -810,6 +810,12 @@
 	  }
       }
 
+    if (ywords[rlen-1] < 0)
+      {
+        ywords[rlen] = 0;
+        rlen++;
+      }
+
     // Now the quotient is in xwords, and the remainder is in ywords.
 
     boolean add_one = false;

I also now noticed a ChangeLog entry which I had managed to overlook
previously - probably because because it was staring right at me at
the top of the ChangeLog!

2000-09-21  Per Bothner  <per@bothner.com>

	* IntNum.java (divide):  Zero-extend results if high-order bit set.

So I believe your patch is basically correct.  However, I think it should
be done before the "add_one" calculation, as in my patch.  Sorry for
not noticing this change earlier - and for that matter, not submitting
the change when I fixed the gnu.math version.
-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/~per/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]