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]

Yet another GCJ update. (a/k/a PR 1615 followup)


Fred compiles and runs well with GCJ. The only problem is the one that's
been plaguing me for over a month now--the BigInteger division bug.

While I wrote GMP support for the low-level MPN functions, the
higher-level functions are in Java, and the GCJ guys like it that way.
There's a bug somewhere in the division methods that occurs when certain
large values are divided. So far, it's been impervious to their debugging
attempts.

The problem does not occur if the divisor is small (I assume small enough
to fit inside a long). That's a lead right there. It also does not occur
if the dividend is small.

And look! You mathematicians will LOVE this!

import java.math.BigInteger;

public class Test {
    public static void main(String[] args) {
        BigInteger x = new BigInteger("10000000000000000000");
        BigInteger y = new BigInteger("4294967296");
        System.out.println(x.divide(y));
    }
}

mjr::mjr$ javac Test.java ; java -cp . Test
2328306436
mjr::mjr$ gcj --main=Test -o test Test.java ; ./test
1156841472
mjr::mjr$

The value of y, "4294967296", is the smallest value of y that will
generate bogus results. "4294967295" will work correctly. "4294967295" =
2^32 - 1! It's also a prime number. (I haven't yet decremented the value
of x to see when it will stop generating bogus results.)

Also note that the incorrect result * 2 = 2313682944, which is 14623492
less than the correct result. The incorrect result in my tests has always
been about half the correct result, but I haven't yet checked to see if
the relative difference is always the same.

You can peruse the problem report from long ago at
http://gcc.gnu.org/cgi-bin/gnatsweb.pl if use the "view" option and enter
"1615" as the PR number.

You can find BigInteger.java at

CHK@J9WTpJLqAfc9Y7yaj1V1JHJdeEQOAwE,qba6avE3DyH6qGsgYIZS1A

or http://24.131.185.22/BigInteger.java. Check out the big scary private
divide method.


-- 
Mark Roberts
mjr@statesmean.com




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