harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r431881 [3/3] - in /incubator/harmony/enhanced/classlib/trunk/modules: luni/src/main/java/java/lang/ math/src/main/java/java/math/ math/src/main/resources/ math/src/test/java/org/apache/harmony/tests/java/math/ math2/
Date Wed, 16 Aug 2006 11:56:04 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/Elementary.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/Elementary.java?rev=431881&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/Elementary.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/Elementary.java Wed Aug 16 04:55:59 2006
@@ -0,0 +1,300 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package java.math;
+
+/**
+ * Static library that provides the basic arithmetic mutable operations for
+ * {@link BigInteger}. The operations that porvides are listed below.
+ * <ul type="circle">
+ * <li>Addition.</li>
+ * <li>Subtraction.</li>
+ * <li>Comparison.</li>
+ * </ul>
+ * In addition to this, some <i><b>Inplace</b></i> (mutable) methods are
+ * provided.
+ * 
+ * @author Daniel Fridlender
+ * @author Matthias Gallé
+ * @author Mariano Heredia
+ * @author Miguel Vasquez
+ */
+class Elementary {
+
+    /** Just to denote that this class can't be instantied */
+    private Elementary() {}
+
+    /**
+     * Compares two arrays. All elements are treated as unsigned integers. The
+     * magnitude is the bit chain of elements in big-endian order.
+     * 
+     * @param a the first array
+     * @param b the second array
+     * @param size the size of arrays
+     * @return 1 if a > b, -1 if a < b, 0 if a == b
+     */
+    static int compareArrays(final int[] a, final int[] b, final int size) {
+        int i;
+        for (i = size - 1; (i >= 0) && (a[i] == b[i]); i--)
+            ;
+        return ((i < 0) ? BigInteger.EQUALS
+                : (a[i] & 0xFFFFFFFFL) < (b[i] & 0xFFFFFFFFL) ? BigInteger.LESS
+                        : BigInteger.GREATER);
+    }
+
+    /** @see BigInteger#add(BigInteger) */
+    static BigInteger add(BigInteger op1, BigInteger op2) {
+        int resDigits[];
+        int resSign;
+        int op1Sign = op1.sign;
+        int op2Sign = op2.sign;
+
+        if (op1Sign == 0) {
+            return op2;
+        }
+        if (op2Sign == 0) {
+            return op1;
+        }
+        int op1Len = op1.numberLength;
+        int op2Len = op2.numberLength;
+
+        if (op1Len + op2Len == 2) {
+            long a = (op1.digits[0] & 0xFFFFFFFFL);
+            long b = (op2.digits[0] & 0xFFFFFFFFL);
+            long res;
+            int valueLo;
+            int valueHi;
+
+            if (op1Sign == op2Sign) {
+                res = a + b;
+                valueLo = (int) res;
+                valueHi = (int) (res >>> 32);
+                return ((valueHi == 0) ? new BigInteger(op1Sign, valueLo)
+                        : new BigInteger(op1Sign, 2, new int[] { valueLo,
+                                valueHi }));
+            } else {
+                return BigInteger.valueOf((op1Sign < 0) ? (b - a) : (a - b));
+            }
+        } else if (op1Sign == op2Sign) {
+            resSign = op1Sign;
+            // an augend should not be shorter than addend
+            resDigits = (op1Len >= op2Len) ? add(op1.digits, op1Len,
+                    op2.digits, op2Len) : add(op2.digits, op2Len, op1.digits,
+                    op1Len);
+        } else { // signs are different
+            int cmp = ((op1Len != op2Len) ? ((op1Len > op2Len) ? 1 : -1)
+                    : compareArrays(op1.digits, op2.digits, op1Len));
+
+            if (cmp == BigInteger.EQUALS) {
+                return BigInteger.ZERO;
+            }
+            // a minuend should not be shorter than subtrahend
+            if (cmp == BigInteger.GREATER) {
+                resSign = op1Sign;
+                resDigits = subtract(op1.digits, op1Len, op2.digits, op2Len);
+            } else {
+                resSign = op2Sign;
+                resDigits = subtract(op2.digits, op2Len, op1.digits, op1Len);
+            }
+        }
+        BigInteger res = new BigInteger(resSign, resDigits.length, resDigits);
+        res.cutOffLeadingZeroes();
+        return res;
+    }
+
+    /**
+     * Performs {@code res = a + b}. It is assumed the magnitude of a is not
+     * less than the magnitude of b.
+     */
+    private static void add(int res[], int a[], int aSize, int b[], int bSize) {
+        // PRE: a[] >= b[]
+        int i;
+        long carry = (a[0] & 0xFFFFFFFFL) + (b[0] & 0xFFFFFFFFL);
+
+        res[0] = (int) carry;
+        carry >>= 32;
+        for (i = 1; i < bSize; i++) {
+            carry += (a[i] & 0xFFFFFFFFL) + (b[i] & 0xFFFFFFFFL);
+            res[i] = (int) carry;
+            carry >>= 32;
+        }
+        for (; i < aSize; i++) {
+            carry += a[i] & 0xFFFFFFFFL;
+            res[i] = (int) carry;
+            carry >>= 32;
+        }
+        res[i] = (int) carry;
+    }
+
+    /**
+     * Addss the value represented by {@code b} to the value represented by
+     * {@code a}. It is assumed the magnitude of a is not less than the
+     * magnitude of b.
+     * 
+     * @return {@code a + b}
+     */
+    private static int[] add(int a[], int aSize, int b[], int bSize) {
+        // PRE: a[] >= b[]
+        int res[] = new int[aSize + 1];
+        add(res, a, aSize, b, bSize);
+        return res;
+    }
+
+    /**
+     * Performs {@code op1 += op2}. {@code op1} must have enough place to store
+     * the result (i.e. {@code op1.bitLength() >= op2.bitLength()}). Both
+     * should be positive (i.e. {@code op1 >= op2}).
+     * 
+     * @param op1 the input minuend, and the ouput result.
+     * @param op2 the addend
+     */
+    static void inplaceAdd(BigInteger op1, BigInteger op2) {
+        // PRE: op1 >= op2 > 0
+        add(op1.digits, op1.digits, op1.numberLength, op2.digits,
+                op2.numberLength);
+        op1.cutOffLeadingZeroes();
+    }
+
+    /**
+     * Adds an integer value to the array of integers remembering carry.
+     * 
+     * @return a possible generated carry (0 or 1)
+     */
+    static int inplaceAdd(int a[], final int aSize, final int addend) {
+        long carry = addend & 0xFFFFFFFFL;
+
+        for (int i = 0; (carry != 0) && (i < aSize); i++) {
+            carry += a[i] & 0xFFFFFFFFL;
+            a[i] = (int) carry;
+            carry >>= 32;
+        }
+        return (int) carry;
+    }
+
+    /**
+     * Performs: {@code op1 += addend}. The number must to have place to hold a
+     * possible carry.
+     */
+    static void inplaceAdd(BigInteger op1, final int addend) {
+        int carry = inplaceAdd(op1.digits, op1.numberLength, addend);
+        if (carry == 1) {
+            op1.digits[op1.numberLength] = 1;
+            op1.numberLength++;
+        }
+    }
+
+    /** @see BigInteger#subtract(BigInteger) */
+    static BigInteger subtract(BigInteger op1, BigInteger op2) {
+        int resSign;
+        int resDigits[];
+        int op1Sign = op1.sign;
+        int op2Sign = op2.sign;
+
+        if (op2Sign == 0) {
+            return op1;
+        }
+        if (op1Sign == 0) {
+            return op2.negate();
+        }
+        int op1Len = op1.numberLength;
+        int op2Len = op2.numberLength;
+        if (op1Len + op2Len == 2) {
+            long a = (op1.digits[0] & 0xFFFFFFFFL);
+            long b = (op2.digits[0] & 0xFFFFFFFFL);
+            if (op1Sign < 0) {
+                a = -a;
+            }
+            if (op2Sign < 0) {
+                b = -b;
+            }
+            return BigInteger.valueOf(a - b);
+        }
+        int cmp = ((op1Len != op2Len) ? ((op1Len > op2Len) ? 1 : -1)
+                : Elementary.compareArrays(op1.digits, op2.digits, op1Len));
+
+        if (cmp == BigInteger.LESS) {
+            resSign = -op2Sign;
+            resDigits = (op1Sign == op2Sign) ? subtract(op2.digits, op2Len,
+                    op1.digits, op1Len) : add(op2.digits, op2Len, op1.digits,
+                    op1Len);
+        } else {
+            resSign = op1Sign;
+            if (op1Sign == op2Sign) {
+                if (cmp == BigInteger.EQUALS) {
+                    return BigInteger.ZERO;
+                }
+                resDigits = subtract(op1.digits, op1Len, op2.digits, op2Len);
+            } else {
+                resDigits = add(op1.digits, op1Len, op2.digits, op2Len);
+            }
+        }
+        BigInteger res = new BigInteger(resSign, resDigits.length, resDigits);
+        res.cutOffLeadingZeroes();
+        return res;
+    }
+
+    /**
+     * Performs {@code res = a - b}. It is assumed the magnitude of a is not
+     * less than the magnitude of b.
+     */
+    private static void subtract(int res[], int a[], int aSize, int b[],
+            int bSize) {
+        // PRE: a[] >= b[]
+        int i;
+        long borrow = 0;
+
+        for (i = 0; i < bSize; i++) {
+            borrow += (a[i] & 0xFFFFFFFFL) - (b[i] & 0xFFFFFFFFL);
+            res[i] = (int) borrow;
+            borrow >>= 32; // -1 or 0
+        }
+        for (; i < aSize; i++) {
+            borrow += a[i] & 0xFFFFFFFFL;
+            res[i] = (int) borrow;
+            borrow >>= 32; // -1 or 0
+        }
+    }
+
+    /**
+     * Subtracts the value represented by {@code b} from the value represented
+     * by {@code a}. It is assumed the magnitude of a is not less than the
+     * magnitude of b.
+     * 
+     * @return {@code a - b}
+     */
+    private static int[] subtract(int a[], int aSize, int b[], int bSize) {
+        // PRE: a[] >= b[]
+        int res[] = new int[aSize];
+        subtract(res, a, aSize, b, bSize);
+        return res;
+    }
+
+    /**
+     * Performs {@code op1 -= op2}. {@code op1} must have enough place to store
+     * the result (i.e. {@code op1.bitLength() >= op2.bitLength()}). Both
+     * should be positive (i.e. {@code op1 >= op2}).
+     * 
+     * @param op1 the input minuend, and the ouput result.
+     * @param op2 the subtrahend
+     */
+    static void inplaceSubtract(BigInteger op1, BigInteger op2) {
+        // PRE: op1 >= op2 > 0
+        subtract(op1.digits, op1.digits, op1.numberLength, op2.digits,
+                op2.numberLength);
+        op1.cutOffLeadingZeroes();
+    }
+
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/Elementary.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/Logical.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/Logical.java?rev=431881&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/Logical.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/Logical.java Wed Aug 16 04:55:59 2006
@@ -0,0 +1,379 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package java.math;
+
+/**
+ * The library implements some logical operations over {@code BigInteger}. The
+ * operations that porvides are listed below.
+ * <ul type="circle">
+ * <li>not</li>
+ * <li>and</li>
+ * <li>or</li>
+ * <li>xor</li>
+ * </ul>
+ * 
+ * @author Daniel Fridlender
+ * @author Matthias Gallé
+ * @author Mariano Heredia
+ * @author Miguel Vasquez
+ */
+class Logical {
+
+    /** Just to denote that this class can't be instantied. */
+    private Logical() {}
+
+    /**
+     * Implements the element by element bitwise operations on two integer
+     * arrays. Arrays can be processed partially starting from 0 element.
+     * 
+     * @param dest the result array
+     * @param a the first source array
+     * @param aLen the number of elements of 'a' to be processed
+     * @param b the second source array
+     * @param bLen the number of elements of 'b' to be processed
+     */
+    static void bitOperation(int dest[], int a[], int aLen, int b[], int bLen,
+            int operation) {
+        int i = 0;
+
+        switch (operation) {
+            case 1: // and
+                for (; i < bLen; i++) {
+                    dest[i] = a[i] & b[i];
+                }
+                break;
+            case 2: // not
+                for (; i < bLen; i++) {
+                    dest[i] = ~b[i];
+                }
+                break;
+            case 3: // or
+                for (; i < bLen; i++) {
+                    dest[i] = a[i] | b[i];
+                }
+                break;
+            case 4: // xor
+                for (; i < bLen; i++) {
+                    dest[i] = a[i] ^ b[i];
+                }
+                break;
+        }
+        while (i < aLen) {
+            dest[i] = a[i++];
+        }
+    }
+
+    /** @see BigInteger#not() */
+    static BigInteger not(BigInteger val) {
+        if (val.sign == 0) {
+            return BigInteger.MINUS_ONE;
+        }
+        int resDigits[] = new int[val.numberLength + 1];
+        int i;
+
+        if (val.sign > 0) {
+            // ~val = -val + 1
+            if (val.digits[val.numberLength - 1] != -1) {
+                for (i = 0; val.digits[i] == -1; i++)
+                    ;
+            } else {
+                for (i = 0; (i < val.numberLength) && (val.digits[i] == -1); i++)
+                    ;
+                if (i == val.numberLength) {
+                    resDigits[i] = 1;
+                    return new BigInteger(-val.sign, i + 1, resDigits);
+                }
+            }
+            // Here a carry 1 was generated
+        } else {// (val.sign < 0)
+            // ~val = -val - 1
+            for (i = 0; val.digits[i] == 0; i++) {
+                resDigits[i] = -1;
+            }
+            // Here a borrow -1 was generated
+        }
+        // Now, the carry/borrow can be absorbed
+        resDigits[i] = val.digits[i] + val.sign;
+        // Coping the remaining unchanged digit
+        for (i++; i < val.numberLength; i++) {
+            resDigits[i] = val.digits[i];
+        }
+        return new BigInteger(-val.sign, i, resDigits);
+    }
+
+    /** @see BigInteger#and(BigInteger) */
+    static BigInteger and(BigInteger val, BigInteger that) {
+        // This let us to throw an eventual NullPointerException if (that ==
+        // null)
+        if (that.sign == 0) {
+            return BigInteger.ZERO;
+        }
+        if (val.sign == 0) {
+            return BigInteger.ZERO;
+        }
+        int resSign = (val.sign & that.sign);
+        int resLength;
+        int resDigits[];
+        int valNeg[] = null;
+        int thatNeg[] = null;
+
+        if (val.sign < 0) {
+            valNeg = new int[val.numberLength];
+            System.arraycopy(val.digits, 0, valNeg, 0, val.numberLength);
+        }
+        if (that.sign < 0) {
+            thatNeg = new int[that.numberLength];
+            System.arraycopy(that.digits, 0, thatNeg, 0, that.numberLength);
+        }
+        // some cases when either val or that is positive
+        if ((val.sign > 0) || (that.sign > 0)) {
+            if ((val.sign > 0) && (that.sign > 0)) {
+                // both are positive;
+                // the number of digits to AND is the length of the shorter
+                // array
+                int andLen = Math.min(val.numberLength, that.numberLength);
+                resLength = andLen;
+                resDigits = new int[resLength];
+                bitOperation(resDigits, val.digits, andLen, that.digits,
+                        andLen, 1);
+            } else {
+                if (val.numberLength > that.numberLength) {
+                    // val is longer than that
+                    if (val.sign > 0) {
+                        // val is positive and that is negative;
+                        // all digits should be and'ed
+                        resLength = val.numberLength;
+                        resDigits = new int[resLength];
+                        BitLevel.setTrueCoded(thatNeg, that.numberLength);
+                        bitOperation(resDigits, val.digits, val.numberLength,
+                                thatNeg, that.numberLength, 1);
+                    } else {
+                        // val is negative and that is positive
+                        // the number of digits to AND is the length of the
+                        // 'that' array
+                        resLength = that.numberLength;
+                        resDigits = new int[resLength];
+                        BitLevel.setTrueCoded(valNeg, val.numberLength);
+                        bitOperation(resDigits, valNeg, that.numberLength,
+                                that.digits, that.numberLength, 1);
+                    }
+                } else {
+                    // val is shorter than that
+                    if (val.sign > 0) {
+                        // val is positive and that is negative;
+                        // the number of digits to AND is the length of the
+                        // 'val' array
+                        resLength = val.numberLength; // + 1?
+                        resDigits = new int[resLength];
+                        BitLevel.setTrueCoded(thatNeg, that.numberLength);
+                        bitOperation(resDigits, thatNeg, val.numberLength,
+                                val.digits, val.numberLength, 1);
+                    } else {
+                        // val is negative and that is positive
+                        // the number of digits to AND is the length of the
+                        // 'that' array
+                        resLength = that.numberLength;
+                        resDigits = new int[resLength];
+                        BitLevel.setTrueCoded(valNeg, val.numberLength);
+                        bitOperation(resDigits, that.digits, that.numberLength,
+                                valNeg, val.numberLength, 1);
+                    }
+                }
+            }
+        } else {
+            // cases when both numbers are negative or
+            // either val or that is positive but both are of the same length
+            if (val.sign < 0) {
+                BitLevel.setTrueCoded(valNeg, val.numberLength);
+            }
+            if (that.sign < 0) {
+                BitLevel.setTrueCoded(thatNeg, that.numberLength);
+            }
+            // The resulting length should have one extra element
+            // for possible carry = 1 returned from BitLevel.setTrueCoded for a
+            // negative number
+            resLength = 1 + Math.max(val.numberLength, that.numberLength);
+            resDigits = new int[resLength];
+            if (val.numberLength >= that.numberLength) {
+                bitOperation(resDigits, (valNeg == null) ? val.digits : valNeg,
+                        val.numberLength, (thatNeg == null) ? that.digits
+                                : thatNeg, that.numberLength, 1);
+            } else {
+                bitOperation(resDigits, (thatNeg == null) ? that.digits
+                        : thatNeg, that.numberLength,
+                        (valNeg == null) ? val.digits : valNeg,
+                        val.numberLength, 1);
+            }
+        }
+        if (resSign < 0) {
+            resDigits[resLength - 1] = BitLevel.setTrueCoded(resDigits,
+                    resLength);
+        }
+        BigInteger result = new BigInteger(resSign, resLength, resDigits);
+        result.cutOffLeadingZeroes();
+        return result;
+    }
+
+    /** @see BigInteger#or(BigInteger) */
+    static BigInteger or(BigInteger val, BigInteger that) {
+        if (that.sign == 0) {
+            return val;
+        }
+        if (val.sign == 0) {
+            return that;
+        }
+        int resSign = (val.sign | that.sign);
+        int resLength;
+        int resDigits[];
+        int valNeg[] = null;
+        int thatNeg[] = null;
+
+        // some cases when either val or that is negative
+        if ((val.sign < 0) || (that.sign < 0)) {
+            if (val.sign < 0) {
+                valNeg = new int[val.numberLength];
+                System.arraycopy(val.digits, 0, valNeg, 0, val.numberLength);
+            }
+            if (that.sign < 0) {
+                thatNeg = new int[that.numberLength];
+                System.arraycopy(that.digits, 0, thatNeg, 0, that.numberLength);
+            }
+            if ((val.sign < 0) && (that.sign < 0)) {
+                // both are negative
+                int orLen = Math.min(val.numberLength, that.numberLength);
+                resLength = orLen + 1;
+                resDigits = new int[resLength];
+                BitLevel.setTrueCoded(valNeg, orLen);
+                BitLevel.setTrueCoded(thatNeg, orLen);
+                bitOperation(resDigits, valNeg, orLen, thatNeg, orLen, 3);
+                resDigits[resLength - 1] = -1;
+            } else {
+                if (val.numberLength > that.numberLength) {
+                    // val is longer than that
+                    if (val.sign > 0) {
+                        // val is positive and that is negative
+                        resLength = that.numberLength + 1;
+                        resDigits = new int[resLength];
+                        BitLevel.setTrueCoded(thatNeg, that.numberLength);
+                        bitOperation(resDigits, val.digits, that.numberLength,
+                                thatNeg, that.numberLength, 3);
+                        resDigits[resLength - 1] = -1;
+                    } else {
+                        // val is negative and that is positive
+                        resLength = val.numberLength;
+                        resDigits = new int[resLength];
+                        BitLevel.setTrueCoded(valNeg, val.numberLength);
+                        bitOperation(resDigits, valNeg, val.numberLength,
+                                that.digits, that.numberLength, 3);
+                    }
+                } else {
+                    // that is longer than val
+                    if (val.sign > 0) {
+                        // val is positive and that is negative
+                        resLength = that.numberLength; // + 1?
+                        resDigits = new int[resLength];
+                        BitLevel.setTrueCoded(thatNeg, that.numberLength);
+                        bitOperation(resDigits, thatNeg, that.numberLength,
+                                val.digits, val.numberLength, 3);
+                    } else {
+                        // that is positive and val is negative
+                        resLength = val.numberLength + 1;
+                        resDigits = new int[resLength];
+                        BitLevel.setTrueCoded(valNeg, val.numberLength);
+                        bitOperation(resDigits, that.digits, val.numberLength,
+                                valNeg, val.numberLength, 3);
+                        resDigits[resLength - 1] = -1;
+                    }
+                }
+            }
+        } else {
+            // cases when both numbers are positive and
+            // either val or that is negative but both are of the same length
+            resLength = Math.max(val.numberLength, that.numberLength);
+            resDigits = new int[resLength];
+            if (val.numberLength >= that.numberLength) {
+                bitOperation(resDigits, (valNeg == null) ? val.digits : valNeg,
+                        val.numberLength, (thatNeg == null) ? that.digits
+                                : thatNeg, that.numberLength, 3);
+            } else {
+                bitOperation(resDigits, (thatNeg == null) ? that.digits
+                        : thatNeg, that.numberLength,
+                        (valNeg == null) ? val.digits : valNeg,
+                        val.numberLength, 3);
+            }
+        }
+        if (resSign < 0) {
+            BitLevel.setTrueCoded(resDigits, resLength);
+        }
+        BigInteger result = new BigInteger(resSign, resLength, resDigits);
+        result.cutOffLeadingZeroes();
+        return result;
+    }
+
+    /** @see BigInteger#xor(BigInteger) */
+    static BigInteger xor(BigInteger val, BigInteger that) {
+        if (that.sign == 0) {
+            return val;
+        }
+        if (val.sign == 0) {
+            return that;
+        }
+        int resSign = (val.sign == that.sign) ? 1 : -1;
+        int resLength = Math.max(val.numberLength, that.numberLength);
+        int resDigits[] = new int[resLength];
+        int valNeg[] = null;
+        int thatNeg[] = null;
+        if (val.sign < 0) {
+            valNeg = new int[val.numberLength];
+            System.arraycopy(val.digits, 0, valNeg, 0, val.numberLength);
+            BitLevel.setTrueCoded(valNeg, val.numberLength);
+        }
+        if (that.sign < 0) {
+            thatNeg = new int[that.numberLength];
+            System.arraycopy(that.digits, 0, thatNeg, 0, that.numberLength);
+            BitLevel.setTrueCoded(thatNeg, that.numberLength);
+        }
+        // First make XOR for N elements where N is the length of a shorter
+        // array.
+        int opLen = Math.min(val.numberLength, that.numberLength);
+        bitOperation(resDigits, (valNeg == null) ? val.digits : valNeg, opLen,
+                (thatNeg == null) ? that.digits : thatNeg, opLen, 4);
+        // Then define top elements.
+        if (val.numberLength != that.numberLength) {
+            int i;
+            for (i = opLen; i < resLength; i++) {
+                if (val.sign == that.sign) {
+                    // the numbers have the same signs
+                    resDigits[i] = ((val.numberLength > that.numberLength) ? (valNeg == null) ? val.digits[i]
+                            : ~valNeg[i]
+                            : (thatNeg == null) ? that.digits[i] : ~thatNeg[i]);
+                } else {
+                    // the numbers have different signs
+                    resDigits[i] = ((val.numberLength >= that.numberLength) ? (val.sign < 0) ? valNeg[i]
+                            : ~val.digits[i]
+                            : (val.sign < 0) ? ~that.digits[i] : thatNeg[i]);
+                }
+            }
+        }
+        if (resSign < 0) {
+            BitLevel.setTrueCoded(resDigits, resLength);
+        }
+        BigInteger result = new BigInteger(resSign, resLength, resDigits);
+        result.cutOffLeadingZeroes();
+        return result;
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/Logical.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/MathContext.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/MathContext.java?rev=431881&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/MathContext.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/MathContext.java Wed Aug 16 04:55:59 2006
@@ -0,0 +1,213 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package java.math;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
+import java.io.StreamCorruptedException;
+
+/**
+ * @ar.org.fitc.spec_ref
+ * @author Daniel Fridlender
+ * @author Matthias Gallé
+ * @author Mariano Heredia
+ * @author Miguel Vasquez 
+ */
+public class MathContext implements Serializable {
+
+    /* Fields */
+
+    /** @ar.org.fitc.spec_ref */
+    public static final MathContext DECIMAL128 = new MathContext(34,
+            RoundingMode.HALF_EVEN);
+
+    /** @ar.org.fitc.spec_ref */
+    public static final MathContext DECIMAL32 = new MathContext(7,
+            RoundingMode.HALF_EVEN);
+
+    /** @ar.org.fitc.spec_ref */
+    public static final MathContext DECIMAL64 = new MathContext(16,
+            RoundingMode.HALF_EVEN);
+
+    /** @ar.org.fitc.spec_ref */
+    public static final MathContext UNLIMITED = new MathContext(0,
+            RoundingMode.HALF_UP);
+
+    /** @ar.org.fitc.spec_ref */
+    private static final long serialVersionUID = 5579720004786848255L;
+
+    /**
+     * The number of digits to be used for an operation; 
+     * results are rounded to this precision.
+     */
+    private int precision;
+
+    /**
+     * A {@code RoundingMode} object which specifies 
+     * the algorithm to be used for rounding.
+     */
+    private RoundingMode roundingMode;
+
+    /** 
+     * An array of {@code char} containing: 
+     * {@code 'p','r','e','c','i','s','i','o','n','='}.
+     * It's used to improve the methods related to {@code String} conversion.
+     * @see #MathContext(String)
+     * @see #toString() 
+     */
+    private final static char[] chPrecision = { 'p', 'r', 'e', 'c', 'i', 's',
+            'i', 'o', 'n', '=' };
+
+    /** 
+     * An array of {@code char} containing: 
+     * {@code 'r','o','u','n','d','i','n','g','M','o','d','e','='}.
+     * It's used to improve the methods related to {@code String} conversion.
+     * @see #MathContext(String)
+     * @see #toString() 
+     */
+    private final static char[] chRoundingMode = { 'r', 'o', 'u', 'n', 'd',
+            'i', 'n', 'g', 'M', 'o', 'd', 'e', '=' };
+
+    /* Constructors */
+
+    /** @ar.org.fitc.spec_ref */
+    public MathContext(int setPrecision) {
+        this(setPrecision, RoundingMode.HALF_UP);
+    }
+
+    /** @ar.org.fitc.spec_ref */
+    public MathContext(int setPrecision, RoundingMode setRoundingMode) {
+        if (setPrecision < 0) {
+            throw new IllegalArgumentException("Digits < 0");
+        }
+        if (setRoundingMode == null) {
+            throw new NullPointerException("null RoundingMode");
+        }
+        precision = setPrecision;
+        roundingMode = setRoundingMode;
+    }
+
+    /** @ar.org.fitc.spec_ref */
+    public MathContext(String val) {
+        char[] charVal = val.toCharArray();
+        int i; // Index of charVal
+        int j; // Index of chRoundingMode
+        int digit; // It will contain the digit parsed
+
+        if ((charVal.length < 27) || (charVal.length > 45)) {
+            throw new IllegalArgumentException("bad string format");
+        }
+        // Parsing "precision=" String
+        for (i = 0; (i < chPrecision.length) && (charVal[i] == chPrecision[i]); i++)
+            ;
+
+        if (i < chPrecision.length) {
+            throw new IllegalArgumentException("bad string format");
+        }
+        // Parsing the value for "precision="...
+        digit = Character.digit(charVal[i], 10);
+        if (digit == -1) {
+            throw new IllegalArgumentException("bad string format");
+        }
+        this.precision = this.precision * 10 + digit;
+        i++;
+
+        do {
+            digit = Character.digit(charVal[i], 10);
+            if (digit == -1) {
+                if (charVal[i] == ' ') {
+                    // It parsed all the digits
+                    i++;
+                    break;
+                } else {// It isn't  a valid digit, and isn't a white space
+                    throw new IllegalArgumentException("bad string format");
+                }
+            }
+            // Acumulating the value parsed
+            this.precision = this.precision * 10 + digit;
+            if (this.precision < 0) {
+                throw new IllegalArgumentException("bad string format");
+            }
+            i++;
+        } while (true);
+        // Parsing "roundingMode="
+        for (j = 0; (j < chRoundingMode.length)
+                && (charVal[i] == chRoundingMode[j]); i++, j++)
+            ;
+
+        if (j < chRoundingMode.length) {
+            throw new IllegalArgumentException("bad string format");
+        }
+        // Parsing the value for "roundingMode"...
+        this.roundingMode = RoundingMode.valueOf(String.valueOf(charVal, i,
+                charVal.length - i));
+    }
+
+    /* Public Methods */
+
+    /** @ar.org.fitc.spec_ref */
+    public int getPrecision() {
+        return precision;
+    }
+
+    /** @ar.org.fitc.spec_ref */
+    public RoundingMode getRoundingMode() {
+        return roundingMode;
+    }
+
+    /** @ar.org.fitc.spec_ref */
+    @Override
+    public boolean equals(Object x) {
+        return ((x instanceof MathContext)
+                && (((MathContext) x).getPrecision() == precision) && (((MathContext) x)
+                .getRoundingMode() == roundingMode));
+    }
+
+    /** @ar.org.fitc.spec_ref */
+    @Override
+    public int hashCode() {
+        // Make place for the necessary bits to represent 8 rounding modes
+        return ((precision << 3) | roundingMode.ordinal());
+    }
+
+    /** @ar.org.fitc.spec_ref */
+    @Override
+    public String toString() {
+        StringBuffer sb = new StringBuffer(45);
+
+        sb.append(chPrecision);
+        sb.append(precision);
+        sb.append(' ');
+        sb.append(chRoundingMode);
+        sb.append(roundingMode);
+        return sb.toString();
+    }
+
+    /** @ar.org.fitc.spec_ref */
+    private void readObject(ObjectInputStream s) throws IOException,
+            ClassNotFoundException {
+        s.defaultReadObject();
+        if (precision < 0) {
+            throw new StreamCorruptedException("bad precision value");
+        }
+        if (roundingMode == null) {
+            throw new StreamCorruptedException("null roundingMode");
+        }
+    }
+
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/MathContext.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/Multiplication.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/Multiplication.java?rev=431881&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/Multiplication.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/Multiplication.java Wed Aug 16 04:55:59 2006
@@ -0,0 +1,336 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package java.math;
+
+/**
+ * Static library that provides all multiplication of {@link BigInteger} methods.
+ *
+ * @author Daniel Fridlender
+ * @author Matthias Gallé
+ * @author Mariano Heredia
+ * @author Miguel Vasquez
+ */
+class Multiplication {
+
+    /** Just to denote that this class can't be instantied. */
+    private Multiplication() {}
+
+    /**
+     * Break point in digits (number of {@code int} elements)
+     * between Karatsuba and Pencil and Paper multiply.
+     */
+    static final int whenUseKaratsuba = 63; // an heuristic value
+
+    static final int tenPows[] = { 1, 10, 100, 1000, 10000, 100000, 1000000,
+            10000000, 100000000, 1000000000 };
+
+    static final BigInteger[] bigTenPows = new BigInteger[32];
+
+    static {
+        int i = 0;
+        long val = 1;
+        for (; i <= 18; i++) {
+            bigTenPows[i] = BigInteger.valueOf(val);
+            val *= 10L;
+        }
+        for (; i < bigTenPows.length; i++) {
+            bigTenPows[i] = bigTenPows[i - 1].multiply(BigInteger.TEN);
+        }
+    }
+
+    /**
+     * Performs a multiplication of two BigInteger and hides the algorithm used.
+     * @see BigInteger#multiply(BigInteger)
+     */
+    static BigInteger multiply(BigInteger x, BigInteger y) {
+        return karatsuba(x, y);
+    }
+
+    /**
+     * Performs the multiplication with the Karatsuba's algorithm.
+     * <b>Karatsuba's algorithm:</b>
+     *<tt>
+     *             u = u<sub>1</sub> * B + u<sub>0</sub><br>
+     *             v = v<sub>1</sub> * B + v<sub>0</sub><br>
+     *
+     *
+     *  u*v = (u<sub>1</sub> * v<sub>1</sub>) * B<sub>2</sub> + ((u<sub>1</sub> - u<sub>0</sub>) * (v<sub>0</sub> - v<sub>1</sub>) + u<sub>1</sub> * v<sub>1</sub> +
+     *  u<sub>0</sub> * v<sub>0</sub> ) * B + u<sub>0</sub> * v<sub>0</sub><br>
+     *</tt>
+     * @param op1 first factor of the product
+     * @param op2 second factor of the product
+     * @return op1*op2
+     * @see #multiply(BigInteger, BigInteger)
+     */
+    static BigInteger karatsuba(BigInteger op1, BigInteger op2) {
+        if (Math.min(op1.numberLength, op2.numberLength) < whenUseKaratsuba) {
+            return multiplyPAP(op2, op1);
+        }
+        BigInteger upperOp1, lowerOp1, upperOp2, lowerOp2;
+        int bitndiv2 = Math.max(op1.numberLength, op2.numberLength) >> 1;
+        int ndiv2 = bitndiv2 << 5;
+        /*  Karatsuba:  u = u1*B + u0
+         *              v = v1*B + v0
+         *
+         *  u*v = (u1*v1)*B^2 + ((u1-u0)*(v0-v1) + u1*v1 + u0*v0)*B + u0*v0
+         */
+        upperOp1 = op1.shiftRight(ndiv2);
+        upperOp2 = op2.shiftRight(ndiv2);
+        lowerOp1 = op1.subtract(upperOp1.shiftLeft(ndiv2));
+        lowerOp2 = op2.subtract(upperOp2.shiftLeft(ndiv2));
+
+        BigInteger upper = karatsuba(upperOp1, upperOp2);
+        BigInteger lower = karatsuba(lowerOp1, lowerOp2);
+        BigInteger middle = karatsuba(upperOp1.subtract(lowerOp1), lowerOp2
+                .subtract(upperOp2));
+        middle = middle.add(upper).add(lower);
+        middle = middle.shiftLeft(ndiv2);
+        upper = upper.shiftLeft(ndiv2 << 1);
+
+        return upper.add(middle).add(lower);
+    }
+
+    /**
+     * Multiplies two BigIntegers.
+     * Implements traditional scholar algorithm described by Knuth.
+     *
+     * <br><tt>
+     *         <table border="0">
+     * <tbody>
+     *
+     *
+     * <tr>
+     * <td align="center">A=</td>
+     * <td>a<sub>3</sub></td>
+     * <td>a<sub>2</sub></td>
+     * <td>a<sub>1</sub></td>
+     * <td>a<sub>0</sub></td>
+     * <td></td>
+     * <td></td>
+     * </tr>
+     *
+     *<tr>
+     * <td align="center">B=</td>
+     * <td></td>
+     * <td>b<sub>2</sub></td>
+     * <td>b<sub>1</sub></td>
+     * <td>b<sub>1</sub></td>
+     * <td></td>
+     * <td></td>
+     * </tr>
+     *
+     * <tr>
+     * <td></td>
+     * <td></td>
+     * <td></td>
+     * <td>b<sub>0</sub>*a<sub>3</sub></td>
+     * <td>b<sub>0</sub>*a<sub>2</sub></td>
+     * <td>b<sub>0</sub>*a<sub>1</sub></td>
+     * <td>b<sub>0</sub>*a<sub>0</sub></td>
+     * </tr>
+     *
+     * <tr>
+     * <td></td>
+     * <td></td>
+     * <td>b<sub>1</sub>*a<sub>3</sub></td>
+     * <td>b<sub>1</sub>*a<sub>2</sub></td>
+     * <td>b<sub>1</sub>*a1</td>
+     * <td>b<sub>1</sub>*a0</td>
+     * </tr>
+     *
+     * <tr>
+     * <td>+</td>
+     * <td>b<sub>2</sub>*a<sub>3</sub></td>
+     * <td>b<sub>2</sub>*a<sub>2</sub></td>
+     * <td>b<sub>2</sub>*a<sub>1</sub></td>
+     * <td>b<sub>2</sub>*a<sub>0</sub></td>
+     * </tr>
+     *
+     *<tr>
+     * <td></td>
+     *<td>______</td>
+     * <td>______</td>
+     * <td>______</td>
+     * <td>______</td>
+     * <td>______</td>
+     * <td>______</td>
+     *</tr>
+     *
+     * <tr>
+     *
+     * <td align="center">A*B=R=</td>
+     * <td align="center">r<sub>5</sub></td>
+     * <td align="center">r<sub>4</sub></td>
+     * <td align="center">r<sub>3</sub></td>
+     * <td align="center">r<sub>2</sub></td>
+     * <td align="center">r<sub>1</sub></td>
+     * <td align="center">r<sub>0</sub></td>
+     * <td></td>
+     * </tr>
+     *
+     * </tbody>
+     * </table>
+     *
+     *</tt>
+     *
+     * @param op1 first factor of the multiplication <code> op1 >= 0 </code>
+     * @param op2 second factor of the multiplication <code> op2 >= 0 </code>
+     * @return a <code>BigInteger</code> of value <code> op1 * op2 </code>
+     */
+    static BigInteger multiplyPAP(BigInteger a, BigInteger b) {
+        BigInteger tmp;
+        if (a.numberLength < b.numberLength) {
+            tmp = a;
+            a = b;
+            b = tmp;
+        }
+        int aLen = a.numberLength;
+        int bLen = b.numberLength;
+        int resLength = aLen + bLen;
+        // a special case when both numbers don't exceed int
+        if (resLength == 2) {
+            long val = ((long) a.digits[0] & 0xFFFFFFFFL)
+                    * ((long) b.digits[0] & 0xFFFFFFFFL);
+            int sign = a.sign != b.sign ? -1 : 1;
+            int valueLo = (int) val;
+            int valueHi = (int) (val >>> 32);
+            return ((valueHi == 0) ? new BigInteger(sign, valueLo)
+                    : new BigInteger(sign, 2, new int[] { valueLo, valueHi }));
+        }
+        int[] aDigits = a.digits;
+        int[] bDigits = b.digits;
+        int resDigits[] = new int[resLength];
+        // common case
+        for (int j = 0; j < bLen; j++) {
+            long carry = 0;
+            int i;
+            for (i = 0; i < aLen; i++) {
+                int m = i + j;
+                carry += ((long) aDigits[i] & 0xFFFFFFFFL)
+                        * ((long) bDigits[j] & 0xFFFFFFFFL)
+                        + ((long) resDigits[m] & 0xFFFFFFFFL);
+                resDigits[m] = (int) carry;
+                carry >>>= 32;
+            }
+            resDigits[i + j] = (int) carry;
+        }
+        BigInteger result = new BigInteger((a.sign == b.sign) ? 1 : -1,
+                resLength, resDigits);
+        result.cutOffLeadingZeroes();
+        return result;
+    }
+
+    /**
+     * Multiplies an array of integers by an integer value.
+     * @param intArray the array of integers
+     * @param arrayLength the number of elements of intArray to be multiplied
+     * @param factor the multiplier
+     * @return the top digit of production
+     */
+    static int multiplyByInt(int intArray[], final int arrayLength,
+            final int factor) {
+        long carry = 0;
+
+        for (int i = 0; i < arrayLength; i++) {
+            carry += ((long) intArray[i] & 0xFFFFFFFFL)
+                    * ((long) factor & 0xFFFFFFFFL);
+            intArray[i] = (int) carry;
+            carry >>>= 32;
+        }
+        return (int) carry;
+    }
+
+    static BigInteger multiplyByPositiveInt(BigInteger a, int b) {
+        int resSign = a.sign;
+        if (resSign == 0) {
+            return BigInteger.ZERO;
+        }
+        int aNumberLength = a.numberLength;
+        int[] aDigits = a.digits;
+        if (aNumberLength == 1) {
+            long res = ((long) aDigits[0] & 0xFFFFFFFFL) * ((long) b);
+            int resLo = (int) res;
+            int resHi = (int) (res >>> 32);
+            if (resHi == 0) {
+                return new BigInteger(resSign, resLo);
+            }
+            return new BigInteger(resSign, 2, new int[] { resLo, resHi });
+        }
+        int resLength = aNumberLength + 1;
+        int resDigits[] = new int[resLength];
+        long carry = 0;
+        // common case
+        int i;
+        for (i = 0; i < aNumberLength; i++) {
+            carry += ((long) aDigits[i] & 0xFFFFFFFFL)
+                    * ((long) b & 0xFFFFFFFFL);
+            resDigits[i] = (int) carry;
+            carry >>>= 32;
+        }
+        resDigits[i] = (int) carry;
+        BigInteger result = new BigInteger(resSign, resLength, resDigits);
+        result.cutOffLeadingZeroes();
+        return result;
+    }
+
+    /**
+     * Multiplies a number by a power of ten.
+     * This method could be used in {@code BigDecimal} class.
+     * @param val the number to be scaled
+     * @param exp a positive exponent
+     * @return {@code val * 10<sup>exp</sup>}
+     */
+    static BigInteger multiplyByTenPow(BigInteger val, int exp) {
+        return ((exp < 10) ? multiplyByPositiveInt(val, tenPows[exp]) : val
+                .multiply(getTenPow(exp)));
+    }
+
+    /**
+     * Generates a power of ten, using the first powers cached in an array. 
+     * @param exp a positive exponent
+     * @return {@code 10<sup>exp</sup>}
+     */
+    static BigInteger getTenPow(int exp) {
+        return ((exp < bigTenPows.length) ? bigTenPows[exp] : BigInteger.TEN
+                .pow(exp));
+    }
+
+    /**
+     * Exponentiation algorithm using squaring algorithm.
+     * @param base
+     * @param exponent must be positive
+     * @ar.org.fitc.ref "http://en.wikipedia.org/wiki/Exponentiating_by_squaring"
+     */
+    static BigInteger pow(BigInteger base, int exponent) {
+        // PRE: exp > 0
+        BigInteger res = BigInteger.ONE;
+        BigInteger acc = base;
+
+        for (; exponent != 1; exponent >>= 1) {
+            if ((exponent & 1) != 0) {
+                // if odd, multiply one more time by acc
+                res = res.multiply(acc);
+            }
+            // acc = base^(2^i)
+            acc = acc.multiply(acc); // squaring            
+        }
+        // exponent == 1, multiply one more time
+        res = res.multiply(acc);
+        return res;
+    }
+
+}
\ No newline at end of file

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/Multiplication.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/Primality.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/Primality.java?rev=431881&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/Primality.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/Primality.java Wed Aug 16 04:55:59 2006
@@ -0,0 +1,286 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package java.math;
+
+import java.util.Arrays;
+import java.util.Random;
+
+/**
+ * Provides primality probabilistic methods.
+ * 
+ * @author Daniel Fridlender
+ * @author Matthias Gallé
+ * @author Mariano Heredia
+ * @author Miguel Vasquez
+ */
+class Primality {
+
+    /** Just to denote that this class can't be instantied. */
+    private Primality() {}
+
+    /* Private Fields */
+
+    /** All prime numbers with bit length lesser than 10 bits. */
+    private static final int primes[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
+            31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101,
+            103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167,
+            173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239,
+            241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313,
+            317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397,
+            401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467,
+            479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569,
+            571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643,
+            647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733,
+            739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823,
+            827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911,
+            919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009,
+            1013, 1019, 1021 };
+
+    /** All {@code BigInteger} prime numbers with bit length lesser than 8 bits. */
+    private static final BigInteger BIprimes[] = new BigInteger[primes.length];
+
+    /**
+     * It encodes how many iterations of Miller-Rabin test are need to get an
+     * error bound not greater than {@code 2<sup>(-100)</sup>}. For example:
+     * for a {@code 1000}-bit number we need {@code 4} iterations, since
+     * {@code BITS[3] < 1000 <= BITS[4]}.
+     */
+    private static final int[] BITS = { 0, 0, 1854, 1233, 927, 747, 627, 543,
+            480, 431, 393, 361, 335, 314, 295, 279, 265, 253, 242, 232, 223,
+            216, 181, 169, 158, 150, 145, 140, 136, 132, 127, 123, 119, 114,
+            110, 105, 101, 96, 92, 87, 83, 78, 73, 69, 64, 59, 54, 49, 44, 38,
+            32, 26, 1 };
+
+    /**
+     * It encodes how many i-bit primes there are in the table for
+     * {@code i=2,...,10}. For example {@code offsetPrimes[6]} says that from
+     * index {@code 11} exists {@code 7} consecutive {@code 6}-bit prime
+     * numbers in the array.
+     */
+    private static final int[][] offsetPrimes = { null, null, { 0, 2 },
+            { 2, 2 }, { 4, 2 }, { 6, 5 }, { 11, 7 }, { 18, 13 }, { 31, 23 },
+            { 54, 43 }, { 97, 75 } };
+
+    static {// To initialize the dual table of BigInteger primes
+        for (int i = 0; i < primes.length; i++) {
+            BIprimes[i] = BigInteger.valueOf(primes[i]);
+        }
+    }
+
+    /* Package Methods */
+
+    /**
+     * It uses the sieve of Eratosthenes to discard several composite numbers in
+     * some appropiate range (at the moment {@code [this, this + 1024]}). After
+     * this process it applies the Miller-Rabin test to the numbers that were
+     * not discarded in the sieve.
+     * 
+     * @see BigInteger#nextProbablePrime()
+     * @see #millerRabin(BigInteger, int)
+     */
+    static BigInteger nextProbablePrime(BigInteger n) {
+        // PRE: n >= 0
+        int i, j;
+        int certainty;
+        int gapSize = 1024; // for searching of the next probable prime number
+        int modules[] = new int[primes.length];
+        boolean isDivisible[] = new boolean[gapSize];
+        BigInteger startPoint;
+        BigInteger probPrime;
+        // If n < "last prime of table" searches next prime in the table
+        if ((n.numberLength == 1) && (n.digits[0] >= 0)
+                && (n.digits[0] < primes[primes.length - 1])) {
+            for (i = 0; n.digits[0] >= primes[i]; i++)
+                ;
+            return BIprimes[i];
+        }
+        /*
+         * Creates a "N" enough big to hold the next probale prime Note that: N <
+         * "next prime" < 2*N
+         */
+        startPoint = new BigInteger(1, n.numberLength,
+                new int[n.numberLength + 1]);
+        System.arraycopy(n.digits, 0, startPoint.digits, 0, n.numberLength);
+        // To fix N to the "next odd number"
+        if (n.testBit(0)) {
+            Elementary.inplaceAdd(startPoint, 2);
+        } else {
+            startPoint.digits[0] |= 1;
+        }
+        // To set the improved certainly of Miller-Rabin
+        j = startPoint.bitLength();
+        for (certainty = 2; j < BITS[certainty]; certainty++)
+            ;
+        // To calculate modules: N mod p1, N mod p2, ... for first primes.
+        for (i = 0; i < primes.length; i++) {
+            modules[i] = Division.remainder(startPoint, primes[i]) - gapSize;
+        }
+        while (true) {
+            // At this point, all numbers in the gap are initializated as
+            // probably primes
+            Arrays.fill(isDivisible, false);
+            // To discard multiples of first primes
+            for (i = 0; i < primes.length; i++) {
+                modules[i] = (modules[i] + gapSize) % primes[i];
+                j = (modules[i] == 0) ? 0 : (primes[i] - modules[i]);
+                for (; j < gapSize; j += primes[i]) {
+                    isDivisible[j] = true;
+                }
+            }
+            // To execute Miller-Rabin for non-divisible numbers by all first
+            // primes
+            for (j = 0; j < gapSize; j++) {
+                if (!isDivisible[j]) {
+                    probPrime = startPoint.clone();
+                    Elementary.inplaceAdd(probPrime, j);
+
+                    if (millerRabin(probPrime, certainty)) {
+                        return probPrime;
+                    }
+                }
+            }
+            Elementary.inplaceAdd(startPoint, gapSize);
+        }
+    }
+
+    /**
+     * A random number is generated until a probable prime number is found.
+     * 
+     * @see BigInteger#BigInteger(int,int,Random)
+     * @see BigInteger#probablePrime(int,Random)
+     * @see #isProbablePrime(BigInteger, int)
+     */
+    static BigInteger consBigInteger(int bitLength, int certainty, Random rnd) {
+        // PRE: bitLength >= 2;
+        // For small numbers get a random prime from the prime table
+        if (bitLength <= 10) {
+            int rp[] = offsetPrimes[bitLength];
+            return BIprimes[rp[0] + rnd.nextInt(rp[1])];
+        }
+        int shiftCount = (-bitLength) & 31;
+        int last = (bitLength + 31) >> 5;
+        BigInteger n = new BigInteger(1, last, new int[last]);
+
+        last--;
+        do {// To fill the array with random integers
+            for (int i = 0; i < n.numberLength; i++) {
+                n.digits[i] = rnd.nextInt();
+            }
+            // To fix to the correct bitLength
+            n.digits[last] |= 0x80000000;
+            n.digits[last] >>>= shiftCount;
+            // To create an odd number
+            n.digits[0] |= 1;
+        } while (!isProbablePrime(n, certainty));
+        return n;
+    }
+
+    /**
+     * @see BigInteger#isProbablePrime(int)
+     * @see #millerRabin(BigInteger, int)
+     * @ar.org.fitc.ref Optimizations: "A. Menezes - Handbook of applied
+     *                  Cryptography, Chapter 4".
+     */
+    static boolean isProbablePrime(BigInteger n, int certainty) {
+        // PRE: n >= 0;
+        if ((certainty <= 0) || ((n.numberLength == 1) && (n.digits[0] == 2))) {
+            return true;
+        }
+        // To discard all even numbers
+        if (!n.testBit(0)) {
+            return false;
+        }
+        // To check if 'n' exists in the table (it fit in 10 bits)
+        if ((n.numberLength == 1) && ((n.digits[0] & 0XFFFFFC00) == 0)) {
+            return (Arrays.binarySearch(primes, n.digits[0]) >= 0);
+        }
+        // To check if 'n' is divisible by some prime of the table
+        for (int i = 1; i < primes.length; i++) {
+            if (Division.remainderArrayByInt(n.digits, n.numberLength,
+                    primes[i]) == 0) {
+                return false;
+            }
+        }
+        // To set the number of iterations necessary for Miller-Rabin test
+        int i;
+        int bitLength = n.bitLength();
+
+        for (i = 2; bitLength < BITS[i]; i++)
+            ;
+        certainty = Math.min(i, 1 + ((certainty - 1) >> 1));
+
+        return millerRabin(n, certainty);
+    }
+
+    /* Private Methods */
+
+    /**
+     * The Miller-Rabin primality test.
+     * 
+     * @param n the input number to be tested.
+     * @param t the number of trials.
+     * @return {@code false} if the number is definitily compose, otherwise
+     *         {@code true} with probability {@code 1 - 4<sup>(-t)</sup>}.
+     * @ar.org.fitc.ref "D. Knuth, The Art of Computer Programming Vo.2, Section
+     *                  4.5.4., Algorithm P"
+     */
+    private static boolean millerRabin(BigInteger n, int t) {
+        // PRE: n >= 0, t >= 0
+        BigInteger x; // x := UNIFORM{2...n-1}
+        BigInteger y; // y := x^(q * 2^j) mod n
+        BigInteger n_minus_1 = n.subtract(BigInteger.ONE); // n-1
+        int bitLength = n_minus_1.bitLength(); // ~ log2(n-1)
+        // (q,k) such that: n-1 = q * 2^k and q is odd
+        int k = n_minus_1.getLowestSetBit();
+        BigInteger q = n_minus_1.shiftRight(k);
+        Random rnd = new Random();
+
+        for (int i = 0; i < t; i++) {
+            // To generate a witness 'x', first it use the primes of table
+            if (i < primes.length) {
+                x = BIprimes[i];
+            } else {/*
+                     * It generates random witness only if it's necesssary. Note
+                     * that all methods would call Miller-Rabin with t <= 50 so
+                     * this part is only to do more robust the algorithm
+                     */
+                do {
+                    x = new BigInteger(bitLength, rnd);
+                } while ((x.compareTo(n) >= BigInteger.EQUALS) || (x.sign == 0)
+                        || x.isOne());
+            }
+            y = x.modPow(q, n);
+            if (y.isOne() || y.equals(n_minus_1)) {
+                continue;
+            }
+            for (int j = 1; j < k; j++) {
+                if (y.equals(n_minus_1)) {
+                    continue;
+                }
+                y = y.multiply(y).mod(n);
+                if (y.isOne()) {
+                    return false;
+                }
+            }
+            if (!y.equals(n_minus_1)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/Primality.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/RoundingMode.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/RoundingMode.java?rev=431881&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/RoundingMode.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/RoundingMode.java Wed Aug 16 04:55:59 2006
@@ -0,0 +1,83 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package java.math;
+
+/**
+ * @ar.org.fitc.spec_ref
+ * @author Daniel Fridlender
+ * @author Matthias Gallé
+ * @author Mariano Heredia
+ * @author Miguel Vasquez 
+ */
+public enum RoundingMode {
+
+    /** @ar.org.fitc.spec_ref */
+    UP(BigDecimal.ROUND_UP),
+
+    /** @ar.org.fitc.spec_ref */
+    DOWN(BigDecimal.ROUND_DOWN),
+
+    /** @ar.org.fitc.spec_ref */
+    CEILING(BigDecimal.ROUND_CEILING),
+
+    /** @ar.org.fitc.spec_ref */
+    FLOOR(BigDecimal.ROUND_FLOOR),
+
+    /** @ar.org.fitc.spec_ref */
+    HALF_UP(BigDecimal.ROUND_HALF_UP),
+
+    /** @ar.org.fitc.spec_ref */
+    HALF_DOWN(BigDecimal.ROUND_HALF_DOWN),
+
+    /** @ar.org.fitc.spec_ref */
+    HALF_EVEN(BigDecimal.ROUND_HALF_EVEN),
+
+    /** @ar.org.fitc.spec_ref */
+    UNNECESSARY(BigDecimal.ROUND_UNNECESSARY);
+
+    /** The old constant of <code>BigDecimal</code>. */
+    protected final int bigDecimalRM;
+
+    /** It sets the old contant. */
+    RoundingMode(int rm) {
+        bigDecimalRM = rm;
+    }
+
+    /** @ar.org.fitc.spec_ref */
+    public static RoundingMode valueOf(int rM) {
+        switch (rM) {
+            case BigDecimal.ROUND_CEILING:
+                return CEILING;
+            case BigDecimal.ROUND_DOWN:
+                return DOWN;
+            case BigDecimal.ROUND_FLOOR:
+                return FLOOR;
+            case BigDecimal.ROUND_HALF_DOWN:
+                return HALF_DOWN;
+            case BigDecimal.ROUND_HALF_EVEN:
+                return HALF_EVEN;
+            case BigDecimal.ROUND_HALF_UP:
+                return HALF_UP;
+            case BigDecimal.ROUND_UNNECESSARY:
+                return UNNECESSARY;
+            case BigDecimal.ROUND_UP:
+                return UP;
+            default:
+                throw new IllegalArgumentException("Invalid rounding mode");
+        }
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/RoundingMode.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalArithmeticTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalArithmeticTest.java?rev=431881&r1=431880&r2=431881&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalArithmeticTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalArithmeticTest.java Wed Aug 16 04:55:59 2006
@@ -489,7 +489,7 @@
             aNumber.divide(bNumber, BigDecimal.ROUND_UNNECESSARY);
             fail("ArithmeticException has not been caught");
         } catch (ArithmeticException e) {
-            assertEquals("Improper exception message", "division by zero", e.getMessage());
+            assertEquals("Improper exception message", "BigInteger divide by zero", e.getMessage());
         }
     }
 
@@ -507,7 +507,7 @@
             aNumber.divide(bNumber, BigDecimal.ROUND_UNNECESSARY);
             fail("ArithmeticException has not been caught");
         } catch (ArithmeticException e) {
-            assertEquals("Improper exception message", "rounding mode is ROUND_UNNECESSARY but the result is not exact", e.getMessage());
+            assertEquals("Improper exception message", "Rounding necessary", e.getMessage());
         }
     }
 
@@ -525,7 +525,7 @@
             aNumber.divide(bNumber, 100);
             fail("IllegalArgumentException has not been caught");
         } catch (IllegalArgumentException e) {
-            assertEquals("Improper exception message", "invalid rounding mode", e.getMessage());
+            assertEquals("Improper exception message", "Invalid rounding mode", e.getMessage());
         }
     }
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalConstructorsTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalConstructorsTest.java?rev=431881&r1=431880&r2=431881&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalConstructorsTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalConstructorsTest.java Wed Aug 16 04:55:59 2006
@@ -71,8 +71,10 @@
         BigDecimal aNumber = new BigDecimal(bA);
         assertEquals("incorrect value", bA, aNumber.unscaledValue());
         assertEquals("incorrect scale", 0, aNumber.scale());
+
+        BigDecimal bd = new BigDecimal((BigInteger) null);
         try {
-        	new BigDecimal((BigInteger) null);
+		bd.toString();
         	fail("No NullPointerException");
         } catch (NullPointerException e) {
         	//expected
@@ -243,7 +245,7 @@
             new BigDecimal(a);
             fail("NumberFormatException has not been caught");
         } catch (NumberFormatException e) {
-            assertEquals("Improper exception message", "argument is NaN", e
+            assertEquals("Improper exception message", "Infinite or NaN", e
                     .getMessage());
         }
     }
@@ -257,7 +259,7 @@
             new BigDecimal(a);
             fail("NumberFormatException has not been caught");
         } catch (NumberFormatException e) {
-            assertEquals("Improper exception message", "argument is infinite",
+            assertEquals("Improper exception message", "Infinite or NaN",
                     e.getMessage());
         }
     }
@@ -271,7 +273,7 @@
             new BigDecimal(a);
             fail("NumberFormatException has not been caught");
         } catch (NumberFormatException e) {
-            assertEquals("Improper exception message", "argument is infinite",
+            assertEquals("Improper exception message", "Infinite or NaN",
                     e.getMessage());
         }
     }
@@ -426,8 +428,6 @@
             new BigDecimal(a);
             fail("NumberFormatException has not been caught");
         } catch (NumberFormatException e) {
-            assertEquals("Improper exception message", "empty exponent", e
-                    .getMessage());
         }
     }
 
@@ -440,8 +440,6 @@
             new BigDecimal(a);
             fail("NumberFormatException has not been caught");
         } catch (NumberFormatException e) {
-            assertEquals("Improper exception message", "empty exponent", e
-                    .getMessage());
         }
     }
 
@@ -455,8 +453,6 @@
             new BigDecimal(a);
             fail("NumberFormatException has not been caught");
         } catch (NumberFormatException e) {
-            assertEquals("Improper exception message",
-                    "exponent is not signed integer", e.getMessage());
         }
     }
 
@@ -470,8 +466,6 @@
             BigDecimal aNumber = new BigDecimal(a);
             fail("NumberFormatException has not been caught");
         } catch (NumberFormatException e) {
-            assertEquals("Improper exception message",
-                    "exponent is not signed integer", e.getMessage());
         }
     }
 
@@ -500,7 +494,7 @@
            new BigDecimal(a);
            fail("NumberFormatException expected");
        } catch (NumberFormatException e) {
-           assertEquals("Improper exception message","resulting scale out of range", 
+           assertEquals("Improper exception message","Scale out of range.", 
                e.getMessage());
        }
     }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalScaleOperationsTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalScaleOperationsTest.java?rev=431881&r1=431880&r2=431881&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalScaleOperationsTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalScaleOperationsTest.java Wed Aug 16 04:55:59 2006
@@ -119,8 +119,7 @@
             BigDecimal bNumber = aNumber.setScale(newScale);
             fail("ArithmeticException has not been caught");
         } catch (ArithmeticException e) {
-            assertTrue("Improper exception message", e.getMessage().
-                equals("rounding mode is ROUND_UNNECESSARY but the result is not exact"));
+            assertEquals("Improper exception message", "Rounding necessary", e.getMessage());
         }
     }
 
@@ -333,7 +332,7 @@
             BigDecimal bNumber = aNumber.movePointRight(shift);
             fail("ArithmeticException has not been caught");
         } catch (ArithmeticException e) {
-            assertEquals("Improper exception message", "scale outside the range of a 32-bit integer", e.getMessage());
+            assertEquals("Improper exception message", "Underflow", e.getMessage());
         }
     }
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerConstructorsTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerConstructorsTest.java?rev=431881&r1=431880&r2=431881&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerConstructorsTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerConstructorsTest.java Wed Aug 16 04:55:59 2006
@@ -40,7 +40,7 @@
             BigInteger aNumber = new BigInteger(aBytes);
             fail("NumberFormatException has not been caught");
         } catch (NumberFormatException e) {
-            assertEquals("Improper exception message", "zero length array", e.getMessage());
+            assertEquals("Improper exception message", "Zero length BigInteger", e.getMessage());
         }
     }
     
@@ -198,7 +198,7 @@
             BigInteger aNumber = new BigInteger(aSign, aBytes);
             fail("NumberFormatException has not been caught");
         } catch (NumberFormatException e) {
-            assertEquals("Improper exception message", "sign must be -1, 0, or 1", e.getMessage());
+            assertEquals("Improper exception message", "Invalid signum value", e.getMessage());
         }
     }
     
@@ -213,7 +213,7 @@
             BigInteger aNumber = new BigInteger(aSign, aBytes);
             fail("NumberFormatException has not been caught");
         } catch (NumberFormatException e) {
-            assertEquals("Improper exception message", "zero sign with non-zero magnitude", e.getMessage());
+            assertEquals("Improper exception message", "signum-magnitude mismatch", e.getMessage());
         }
     }
 
@@ -580,7 +580,7 @@
             BigInteger aNumber = new BigInteger(value, radix);
             fail("NumberFormatException has not been caught");
         } catch (NumberFormatException e) {
-            assertEquals("Improper exception message", "radix is out of range", e.getMessage());
+            assertEquals("Improper exception message", "Radix out of range", e.getMessage());
         }
     }
     

Modified: incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerDivideTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerDivideTest.java?rev=431881&r1=431880&r2=431881&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerDivideTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerDivideTest.java Wed Aug 16 04:55:59 2006
@@ -42,7 +42,7 @@
             BigInteger result = aNumber.divide(bNumber);
             fail("ArithmeticException has not been caught");
         } catch (ArithmeticException e) {
-            assertEquals("Improper exception message", "division by zero", e.getMessage());
+            assertEquals("Improper exception message", "BigInteger divide by zero", e.getMessage());
         }
     }
 
@@ -58,7 +58,7 @@
             BigInteger result = aNumber.divide(bNumber);
             fail("ArithmeticException has not been caught");
         } catch (ArithmeticException e) {
-            assertEquals("Improper exception message", "division by zero", e.getMessage());
+            assertEquals("Improper exception message", "BigInteger divide by zero", e.getMessage());
         }
     }
 
@@ -411,7 +411,7 @@
             BigInteger result = aNumber.remainder(bNumber);
             fail("ArithmeticException has not been caught");
         } catch (ArithmeticException e) {
-            assertEquals("Improper exception message", "division by zero", e.getMessage());
+            assertEquals("Improper exception message", "BigInteger divide by zero", e.getMessage());
         }
     }
 
@@ -624,7 +624,7 @@
             BigInteger result = aNumber.mod(bNumber);
             fail("ArithmeticException has not been caught");
         } catch (ArithmeticException e) {
-            assertEquals("Improper exception message", "modulus is non-positive", e.getMessage());
+            assertEquals("Improper exception message", "BigInteger: modulus not positive", e.getMessage());
         }
     }
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerModPowTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerModPowTest.java?rev=431881&r1=431880&r2=431881&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerModPowTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerModPowTest.java Wed Aug 16 04:55:59 2006
@@ -45,7 +45,7 @@
 			BigInteger result = aNumber.modPow(exp, modulus);
 			fail("ArithmeticException has not been caught");
 		} catch (ArithmeticException e) {
-			assertEquals("Improper exception message", "non-positive modulus", e.getMessage());
+			assertEquals("Improper exception message", "BigInteger: modulus not positive", e.getMessage());
 		}
 	}
 
@@ -109,7 +109,7 @@
 			BigInteger result = aNumber.modInverse(modulus);
 			fail("ArithmeticException has not been caught");
 		} catch (ArithmeticException e) {
-			assertEquals("Improper exception message", "non-positive modulus", e.getMessage());
+			assertEquals("Improper exception message", "BigInteger: modulus not positive", e.getMessage());
 		}
 	}
 	
@@ -127,7 +127,7 @@
 			BigInteger result = aNumber.modInverse(modulus);
 			fail("ArithmeticException has not been caught");
 		} catch (ArithmeticException e) {
-			assertEquals("Improper exception message", "non-invertible BigInteger", e.getMessage());
+			assertEquals("Improper exception message", "BigInteger not invertible.", e.getMessage());
 		}
 	}
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerMultiplyTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerMultiplyTest.java?rev=431881&r1=431880&r2=431881&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerMultiplyTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerMultiplyTest.java Wed Aug 16 04:55:59 2006
@@ -285,7 +285,7 @@
             BigInteger result = aNumber.pow(exp);
             fail("ArithmeticException has not been caught");
         } catch (ArithmeticException e) {
-            assertEquals("Improper exception message", "exponent is negative", e.getMessage());
+            assertEquals("Improper exception message", "Negative exponent", e.getMessage());
         }
     }
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerOperateBitsTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerOperateBitsTest.java?rev=431881&r1=431880&r2=431881&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerOperateBitsTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerOperateBitsTest.java Wed Aug 16 04:55:59 2006
@@ -133,7 +133,7 @@
             BigInteger result = aNumber.clearBit(number);
             fail("ArithmeticException has not been caught");
         } catch (ArithmeticException e) {
-            assertEquals("Improper exception message", "negative bit number", e.getMessage());
+            assertEquals("Improper exception message", "Negative bit address", e.getMessage());
         }
     }
 
@@ -440,7 +440,7 @@
             BigInteger result = aNumber.flipBit(number);
             fail("ArithmeticException has not been caught");
         } catch (ArithmeticException e) {
-            assertEquals("Improper exception message", "negative bit number", e.getMessage());
+            assertEquals("Improper exception message", "Negative bit address", e.getMessage());
         }
     }
 
@@ -730,7 +730,7 @@
             BigInteger result = aNumber.setBit(number);
             fail("ArithmeticException has not been caught");
         } catch (ArithmeticException e) {
-            assertEquals("Improper exception message", "negative bit number", e.getMessage());
+            assertEquals("Improper exception message", "Negative bit address", e.getMessage());
         }
     }
 
@@ -1307,7 +1307,7 @@
             boolean result = aNumber.testBit(number);
             fail("ArithmeticException has not been caught");
         } catch (ArithmeticException e) {
-            assertEquals("Improper exception message", "negative bit number", e.getMessage());
+            assertEquals("Improper exception message", "Negative bit address", e.getMessage());
         }
     }
 



Mime
View raw message