--- old/src/share/classes/java/math/BigInteger.java 2013-11-08 15:24:39.000000000 -0800 +++ new/src/share/classes/java/math/BigInteger.java 2013-11-08 15:24:38.000000000 -0800 @@ -2010,39 +2010,6 @@ // Division /** - * Returns a BigInteger whose value is {@code (this / val)}. - * - * @param val value by which this BigInteger is to be divided. - * @return {@code this / val} - * @throws ArithmeticException if {@code val} is zero. - */ - public BigInteger divide(BigInteger val) { - if (mag.length < BURNIKEL_ZIEGLER_THRESHOLD || - val.mag.length < BURNIKEL_ZIEGLER_THRESHOLD) { - return divideKnuth(val); - } else { - return divideBurnikelZiegler(val); - } - } - - /** - * Returns a BigInteger whose value is {@code (this / val)} using an O(n^2) algorithm from Knuth. - * - * @param val value by which this BigInteger is to be divided. - * @return {@code this / val} - * @throws ArithmeticException if {@code val} is zero. - * @see MutableBigInteger#divideKnuth(MutableBigInteger, MutableBigInteger, boolean) - */ - private BigInteger divideKnuth(BigInteger val) { - MutableBigInteger q = new MutableBigInteger(), - a = new MutableBigInteger(this.mag), - b = new MutableBigInteger(val.mag); - - a.divideKnuth(b, q, false); - return q.toBigInteger(this.signum * val.signum); - } - - /** * Returns an array of two BigIntegers containing {@code (this / val)} * followed by {@code (this % val)}. * @@ -2054,82 +2021,37 @@ * @throws ArithmeticException if {@code val} is zero. */ public BigInteger[] divideAndRemainder(BigInteger val) { - if (mag.length < BURNIKEL_ZIEGLER_THRESHOLD || - val.mag.length < BURNIKEL_ZIEGLER_THRESHOLD) { - return divideAndRemainderKnuth(val); - } else { - return divideAndRemainderBurnikelZiegler(val); - } - } - - /** Long division */ - private BigInteger[] divideAndRemainderKnuth(BigInteger val) { - BigInteger[] result = new BigInteger[2]; MutableBigInteger q = new MutableBigInteger(), a = new MutableBigInteger(this.mag), b = new MutableBigInteger(val.mag); - MutableBigInteger r = a.divideKnuth(b, q); + MutableBigInteger r = a.divide(b, q, true); + BigInteger[] result = new BigInteger[2]; result[0] = q.toBigInteger(this.signum == val.signum ? 1 : -1); result[1] = r.toBigInteger(this.signum); return result; } /** - * Returns a BigInteger whose value is {@code (this % val)}. + * Returns a BigInteger whose value is {@code (this / val)}. * - * @param val value by which this BigInteger is to be divided, and the - * remainder computed. - * @return {@code this % val} - * @throws ArithmeticException if {@code val} is zero. - */ - public BigInteger remainder(BigInteger val) { - if (mag.length < BURNIKEL_ZIEGLER_THRESHOLD || - val.mag.length < BURNIKEL_ZIEGLER_THRESHOLD) { - return remainderKnuth(val); - } else { - return remainderBurnikelZiegler(val); - } - } - - /** Long division */ - private BigInteger remainderKnuth(BigInteger val) { - MutableBigInteger q = new MutableBigInteger(), - a = new MutableBigInteger(this.mag), - b = new MutableBigInteger(val.mag); - - return a.divideKnuth(b, q).toBigInteger(this.signum); - } - - /** - * Calculates {@code this / val} using the Burnikel-Ziegler algorithm. - * @param val the divisor + * @param val value by which this BigInteger is to be divided. * @return {@code this / val} + * @throws ArithmeticException if {@code val} is zero. */ - private BigInteger divideBurnikelZiegler(BigInteger val) { - return divideAndRemainderBurnikelZiegler(val)[0]; + public BigInteger divide(BigInteger val) { + return divideAndRemainder(val)[0]; } /** - * Calculates {@code this % val} using the Burnikel-Ziegler algorithm. - * @param val the divisor + * Returns a BigInteger whose value is {@code (this % val)}. + * + * @param val value by which this BigInteger is to be divided, and the + * remainder computed. * @return {@code this % val} + * @throws ArithmeticException if {@code val} is zero. */ - private BigInteger remainderBurnikelZiegler(BigInteger val) { - return divideAndRemainderBurnikelZiegler(val)[1]; - } - - /** - * Computes {@code this / val} and {@code this % val} using the - * Burnikel-Ziegler algorithm. - * @param val the divisor - * @return an array containing the quotient and remainder - */ - private BigInteger[] divideAndRemainderBurnikelZiegler(BigInteger val) { - MutableBigInteger q = new MutableBigInteger(); - MutableBigInteger r = new MutableBigInteger(this).divideAndRemainderBurnikelZiegler(new MutableBigInteger(val), q); - BigInteger qBigInt = q.isZero() ? ZERO : q.toBigInteger(signum*val.signum); - BigInteger rBigInt = r.isZero() ? ZERO : r.toBigInteger(signum); - return new BigInteger[] {qBigInt, rBigInt}; + public BigInteger remainder(BigInteger val) { + return divideAndRemainder(val)[1]; } /**