[9] RFR of 8032027: Add BigInteger square root methods

Brian Burkhalter brian.burkhalter at oracle.com
Thu Dec 10 22:32:55 UTC 2015


A new version is here:

http://cr.openjdk.java.net/~bpb/8032027/webrev.05/

I changed the test to verify these values:

        Stream.Builder<BigInteger> sb = Stream.builder();
        int maxExponent = Double.MAX_EXPONENT + 1;
        for (int i = 1; i <= maxExponent; i++) {
            BigInteger p2 = BigInteger.ONE.shiftLeft(i);
            sb.add(p2.subtract(BigInteger.ONE));
            sb.add(p2);
            sb.add(p2.add(BigInteger.ONE));
        }
        sb.add((new BigDecimal(Double.MAX_VALUE)).toBigInteger());
        sb.add((new BigDecimal(Double.MAX_VALUE)).toBigInteger().add(BigInteger.ONE));
        report("squareRoot for 2^N and 2^N - 1, 1 <= N <= Double.MAX_EXPONENT",
            sb.build().collect(Collectors.summingInt(f)));

At line 1892 of the current version of MutableBigInteger I changed "if (bitLength() < 63)" to "if (bitLength() <= 63)". I realized that in that case the entire calculation might as well be done in longs so I changed it accordingly. The modified test passes with this new revision.

Thanks,

Brian

On Dec 9, 2015, at 6:11 PM, Joseph D. Darcy <Joe.Darcy at Oracle.Com> wrote:

> New version looks good.
> 
> One more case to try: start with a BigInteger that would overflow to Double.POSITIVE_INFINITY when the doubleValue method was called. If this case doesn't take too long to run, it would be a fine additional case to add to the test. 2^1024 should be fine input value. More precisely, 
> 
>      (new BigDecimal(Double.MAX_VALUE)).toBigInteger().add(BigInteger.ONE);
> 
> should do the trick. If the code passes with this value, you're okay to push. Well, while you're at it, might as well verify
> 
>     (new BigDecimal(Double.MAX_VALUE)).toBigInteger()
> 
> behaves well too ;-)


On Dec 9, 2015, at 6:22 PM, Louis Wasserman <wasserman.louis at gmail.com> wrote:

> Guava's tests check the explicit definition of square root (mentioned by Joe above) on 2^n +/- 1 for all n up to Double.MAX_EXPONENT + 1, because why not?





More information about the core-libs-dev mailing list