commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r772119 [2/2] - in /commons/proper/math/trunk/src/java/org/apache/commons/math: ./ complex/ distribution/ fraction/ geometry/ linear/ ode/ random/ stat/ stat/descriptive/ stat/descriptive/moment/ stat/descriptive/rank/ stat/regression/ util/
Date Wed, 06 May 2009 09:43:30 GMT
Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/BigMatrixImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/BigMatrixImpl.java?rev=772119&r1=772118&r2=772119&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/BigMatrixImpl.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/BigMatrixImpl.java Wed May  6 09:43:28 2009
@@ -102,9 +102,15 @@
      *  positive
      */
     public BigMatrixImpl(int rowDimension, int columnDimension) {
-        if (rowDimension <=0 || columnDimension <=0) {
-            throw new IllegalArgumentException
-            ("row and column dimensions must be positive");
+        if (rowDimension <= 0 ) {
+            throw MathRuntimeException.createIllegalArgumentException(
+                    "invalid row dimension {0} (must be positive)",
+                    rowDimension);
+        }
+        if (columnDimension <= 0) {
+            throw MathRuntimeException.createIllegalArgumentException(
+                    "invalid column dimension {0} (must be positive)",
+                    columnDimension);
         }
         data = new BigDecimal[rowDimension][columnDimension];
         lu = null;
@@ -151,15 +157,18 @@
             }   
             final int nRows = d.length;
             if (nRows == 0) {
-                throw new IllegalArgumentException("Matrix must have at least one row."); 
+                throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row"); 
             }
+
             final int nCols = d[0].length;
             if (nCols == 0) {
-                throw new IllegalArgumentException("Matrix must have at least one column."); 
+                throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column"); 
             }
             for (int r = 1; r < nRows; r++) {
                 if (d[r].length != nCols) {
-                    throw new IllegalArgumentException("All input rows must have the same length.");
+                    throw MathRuntimeException.createIllegalArgumentException(
+                          "some rows have length {0} while others have length {1}",
+                          nCols, d[r].length); 
                 }
             }       
             data = d;
@@ -181,18 +190,18 @@
     public BigMatrixImpl(double[][] d) {
         final int nRows = d.length;
         if (nRows == 0) {
-            throw new IllegalArgumentException(
-            "Matrix must have at least one row."); 
+            throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row"); 
         }
+
         final int nCols = d[0].length;
         if (nCols == 0) {
-            throw new IllegalArgumentException(
-            "Matrix must have at least one column."); 
+            throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column"); 
         }
         for (int row = 1; row < nRows; row++) {
             if (d[row].length != nCols) {
-                throw new IllegalArgumentException(
-                "All input rows must have the same length.");
+                throw MathRuntimeException.createIllegalArgumentException(
+                      "some rows have length {0} while others have length {1}",
+                      nCols, d[row].length); 
             }
         }
         this.copyIn(d);
@@ -211,18 +220,18 @@
     public BigMatrixImpl(String[][] d) {
         final int nRows = d.length;
         if (nRows == 0) {
-            throw new IllegalArgumentException(
-            "Matrix must have at least one row."); 
+            throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row"); 
         }
+
         final int nCols = d[0].length;
         if (nCols == 0) {
-            throw new IllegalArgumentException(
-            "Matrix must have at least one column."); 
+            throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column"); 
         }
         for (int row = 1; row < nRows; row++) {
             if (d[row].length != nCols) {
-                throw new IllegalArgumentException(
-                "All input rows must have the same length.");
+                throw MathRuntimeException.createIllegalArgumentException(
+                      "some rows have length {0} while others have length {1}",
+                      nCols, d[row].length); 
             }
         }
         this.copyIn(d);
@@ -266,11 +275,12 @@
         try {
             return add((BigMatrixImpl) m);
         } catch (ClassCastException cce) {
+
+            // safety check
+            MatrixUtils.checkAdditionCompatible(this, m);
+
             final int rowCount    = getRowDimension();
             final int columnCount = getColumnDimension();
-            if (columnCount != m.getColumnDimension() || rowCount != m.getRowDimension()) {
-                throw new IllegalArgumentException("matrix dimension mismatch");
-            }
             final BigDecimal[][] outData = new BigDecimal[rowCount][columnCount];
             for (int row = 0; row < rowCount; row++) {
                 final BigDecimal[] dataRow    = data[row];
@@ -291,11 +301,12 @@
      * @throws  IllegalArgumentException if m is not the same size as this
      */
     public BigMatrixImpl add(BigMatrixImpl m) throws IllegalArgumentException {
+
+        // safety check
+        MatrixUtils.checkAdditionCompatible(this, m);
+
         final int rowCount    = getRowDimension();
         final int columnCount = getColumnDimension();
-        if (columnCount != m.getColumnDimension() || rowCount != m.getRowDimension()) {
-            throw new IllegalArgumentException("matrix dimension mismatch");
-        }
         final BigDecimal[][] outData = new BigDecimal[rowCount][columnCount];
         for (int row = 0; row < rowCount; row++) {
             final BigDecimal[] dataRow    = data[row];
@@ -319,11 +330,12 @@
         try {
             return subtract((BigMatrixImpl) m);
         } catch (ClassCastException cce) {
+
+            // safety check
+            MatrixUtils.checkSubtractionCompatible(this, m);
+
             final int rowCount    = getRowDimension();
             final int columnCount = getColumnDimension();
-            if (columnCount != m.getColumnDimension() || rowCount != m.getRowDimension()) {
-                throw new IllegalArgumentException("matrix dimension mismatch");
-            }
             final BigDecimal[][] outData = new BigDecimal[rowCount][columnCount];
             for (int row = 0; row < rowCount; row++) {
                 final BigDecimal[] dataRow    = data[row];
@@ -344,11 +356,12 @@
      * @throws  IllegalArgumentException if m is not the same size as this
      */
     public BigMatrixImpl subtract(BigMatrixImpl m) throws IllegalArgumentException {
+
+        // safety check
+        MatrixUtils.checkSubtractionCompatible(this, m);
+
         final int rowCount    = getRowDimension();
         final int columnCount = getColumnDimension();
-        if (columnCount != m.getColumnDimension() || rowCount != m.getRowDimension()) {
-            throw new IllegalArgumentException("matrix dimension mismatch");
-        }
         final BigDecimal[][] outData = new BigDecimal[rowCount][columnCount];
         for (int row = 0; row < rowCount; row++) {
             final BigDecimal[] dataRow    = data[row];
@@ -411,9 +424,10 @@
         try {
             return multiply((BigMatrixImpl) m);
         } catch (ClassCastException cce) {
-            if (this.getColumnDimension() != m.getRowDimension()) {
-                throw new IllegalArgumentException("Matrices are not multiplication compatible.");
-            }
+
+            // safety check
+            MatrixUtils.checkMultiplicationCompatible(this, m);
+
             final int nRows = this.getRowDimension();
             final int nCols = m.getColumnDimension();
             final int nSum = this.getColumnDimension();
@@ -441,9 +455,10 @@
      *             if columnDimension(this) != rowDimension(m)
      */
     public BigMatrixImpl multiply(BigMatrixImpl m) throws IllegalArgumentException {
-        if (this.getColumnDimension() != m.getRowDimension()) {
-            throw new IllegalArgumentException("Matrices are not multiplication compatible.");
-        }
+
+        // safety check
+        MatrixUtils.checkMultiplicationCompatible(this, m);
+
         final int nRows = this.getRowDimension();
         final int nCols = m.getColumnDimension();
         final int nSum = this.getColumnDimension();
@@ -587,15 +602,15 @@
                                   int startColumn, int endColumn)
         throws MatrixIndexException {
 
-        checkRowIndex(startRow);
-        checkRowIndex(endRow);
+        MatrixUtils.checkRowIndex(this, startRow);
+        MatrixUtils.checkRowIndex(this, endRow);
         if (startRow > endRow) {
             throw new MatrixIndexException("initial row {0} after final row {1}",
                                            startRow, endRow);
         }
 
-        checkColumnIndex(startColumn);
-        checkColumnIndex(endColumn);
+        MatrixUtils.checkColumnIndex(this, startColumn);
+        MatrixUtils.checkColumnIndex(this, endColumn);
         if (startColumn > endColumn) {
             throw new MatrixIndexException("initial column {0} after final column {1}",
                                            startColumn, endColumn);
@@ -648,10 +663,10 @@
             // we redo the loop with checks enabled
             // in order to generate an appropriate message
             for (final int row : selectedRows) {
-                checkRowIndex(row);
+                MatrixUtils.checkRowIndex(this, row);
             }
             for (final int column : selectedColumns) {
-                checkColumnIndex(column);
+                MatrixUtils.checkColumnIndex(this, column);
             }
         }
         return new BigMatrixImpl(subMatrixData, false);
@@ -688,18 +703,20 @@
     throws MatrixIndexException {
 
         final int nRows = subMatrix.length;
-        final int nCols = subMatrix[0].length;
-
         if (nRows == 0) {
-            throw new IllegalArgumentException("Matrix must have at least one row."); 
+            throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row"); 
         }
+
+        final int nCols = subMatrix[0].length;
         if (nCols == 0) {
-            throw new IllegalArgumentException("Matrix must have at least one column."); 
+            throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column"); 
         }
 
         for (int r = 1; r < nRows; r++) {
             if (subMatrix[r].length != nCols) {
-                throw new IllegalArgumentException("All input rows must have the same length.");
+                throw MathRuntimeException.createIllegalArgumentException(
+                      "some rows have length {0} while others have length {1}",
+                      nCols, subMatrix[r].length); 
             }
         }
 
@@ -717,10 +734,10 @@
             data = new BigDecimal[nRows][nCols];
             System.arraycopy(subMatrix, 0, data, 0, subMatrix.length);          
         } else {
-            checkRowIndex(row);
-            checkColumnIndex(column);
-            checkRowIndex(nRows + row - 1);
-            checkColumnIndex(nCols + column - 1);
+            MatrixUtils.checkRowIndex(this, row);
+            MatrixUtils.checkColumnIndex(this, column);
+            MatrixUtils.checkRowIndex(this, nRows + row - 1);
+            MatrixUtils.checkColumnIndex(this, nCols + column - 1);
         }
         for (int i = 0; i < nRows; i++) {
             System.arraycopy(subMatrix[i], 0, data[row + i], column, nCols);
@@ -739,7 +756,7 @@
      * @throws MatrixIndexException if the specified row index is invalid
      */
     public BigMatrix getRowMatrix(int row) throws MatrixIndexException {
-        checkRowIndex(row);
+        MatrixUtils.checkRowIndex(this, row);
         final int ncols = this.getColumnDimension();
         final BigDecimal[][] out = new BigDecimal[1][ncols]; 
         System.arraycopy(data[row], 0, out[0], 0, ncols);
@@ -755,7 +772,7 @@
      * @throws MatrixIndexException if the specified column index is invalid
      */
     public BigMatrix getColumnMatrix(int column) throws MatrixIndexException {
-        checkColumnIndex(column);
+        MatrixUtils.checkColumnIndex(this, column);
         final int nRows = this.getRowDimension();
         final BigDecimal[][] out = new BigDecimal[nRows][1]; 
         for (int row = 0; row < nRows; row++) {
@@ -775,7 +792,7 @@
      * @throws MatrixIndexException if the specified row index is not valid
      */
     public BigDecimal[] getRow(int row) throws MatrixIndexException {
-        checkRowIndex(row);
+        MatrixUtils.checkRowIndex(this, row);
         final int ncols = this.getColumnDimension();
         final BigDecimal[] out = new BigDecimal[ncols];
         System.arraycopy(data[row], 0, out, 0, ncols);
@@ -794,7 +811,7 @@
      * @throws MatrixIndexException if the specified row index is not valid
      */
     public double[] getRowAsDoubleArray(int row) throws MatrixIndexException {
-        checkRowIndex(row);
+        MatrixUtils.checkRowIndex(this, row);
         final int ncols = this.getColumnDimension();
         final double[] out = new double[ncols];
         for (int i=0;i<ncols;i++) {
@@ -814,7 +831,7 @@
      * @throws MatrixIndexException if the specified column index is not valid
      */
     public BigDecimal[] getColumn(int col) throws MatrixIndexException {
-        checkColumnIndex(col);
+        MatrixUtils.checkColumnIndex(this, col);
         final int nRows = this.getRowDimension();
         final BigDecimal[] out = new BigDecimal[nRows];
         for (int i = 0; i < nRows; i++) {
@@ -835,7 +852,7 @@
      * @throws MatrixIndexException if the specified column index is not valid
      */
     public double[] getColumnAsDoubleArray(int col) throws MatrixIndexException {
-        checkColumnIndex(col);
+        MatrixUtils.checkColumnIndex(this, col);
         final int nrows = this.getRowDimension();
         final double[] out = new double[nrows];
         for (int i=0;i<nrows;i++) {
@@ -1487,31 +1504,4 @@
         lu = null;
     }
 
-    /**
-     * Check if a row index is valid.
-     * @param row row index to check
-     * @exception MatrixIndexException if index is not valid
-     */
-    private void checkRowIndex(final int row) {
-        if (row < 0 || row >= getRowDimension()) {
-            throw new MatrixIndexException(
-                    "row index {0} out of allowed range [{1}, {2}]",
-                    row, 0, getRowDimension() - 1);
-        }
-    }
-
-    /**
-     * Check if a column index is valid.
-     * @param column column index to check
-     * @exception MatrixIndexException if index is not valid
-     */
-    private void checkColumnIndex(final int column)
-        throws MatrixIndexException {
-        if (column < 0 || column >= getColumnDimension()) {
-            throw new MatrixIndexException(
-                    "column index {0} out of allowed range [{1}, {2}]",
-                    column, 0, getColumnDimension() - 1);
-        }
-    }
-
 }

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/DenseRealMatrix.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/DenseRealMatrix.java?rev=772119&r1=772118&r2=772119&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/DenseRealMatrix.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/DenseRealMatrix.java Wed May  6 09:43:28 2009
@@ -311,7 +311,7 @@
         } catch (ClassCastException cce) {
 
             // safety check
-            checkAdditionCompatible(m);
+            MatrixUtils.checkAdditionCompatible(this, m);
 
             final DenseRealMatrix out = new DenseRealMatrix(rows, columns);
 
@@ -355,7 +355,7 @@
         throws IllegalArgumentException {
 
         // safety check
-        checkAdditionCompatible(m);
+        MatrixUtils.checkAdditionCompatible(this, m);
 
         final DenseRealMatrix out = new DenseRealMatrix(rows, columns);
 
@@ -382,7 +382,7 @@
         } catch (ClassCastException cce) {
 
             // safety check
-            checkSubtractionCompatible(m);
+            MatrixUtils.checkSubtractionCompatible(this, m);
 
             final DenseRealMatrix out = new DenseRealMatrix(rows, columns);
 
@@ -426,7 +426,7 @@
         throws IllegalArgumentException {
 
         // safety check
-        checkSubtractionCompatible(m);
+        MatrixUtils.checkSubtractionCompatible(this, m);
 
         final DenseRealMatrix out = new DenseRealMatrix(rows, columns);
 
@@ -493,7 +493,7 @@
         } catch (ClassCastException cce) {
 
             // safety check
-            checkMultiplicationCompatible(m);
+            MatrixUtils.checkMultiplicationCompatible(this, m);
 
             final DenseRealMatrix out = new DenseRealMatrix(rows, m.getColumnDimension());
 
@@ -552,7 +552,7 @@
     public DenseRealMatrix multiply(DenseRealMatrix m) throws IllegalArgumentException {
 
         // safety check
-        checkMultiplicationCompatible(m);
+        MatrixUtils.checkMultiplicationCompatible(this, m);
 
         final DenseRealMatrix out = new DenseRealMatrix(rows, m.columns);
 
@@ -686,7 +686,7 @@
         throws MatrixIndexException {
 
         // safety checks
-        checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
+        MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
 
         // create the output matrix
         final DenseRealMatrix out =
@@ -815,7 +815,7 @@
         }
         final int endRow    = row + subMatrix.length - 1;
         final int endColumn = column + refLength - 1;
-        checkSubMatrixIndex(row, endRow, column, endColumn);
+        MatrixUtils.checkSubMatrixIndex(this, row, endRow, column, endColumn);
         for (final double[] subRow : subMatrix) {
             if (subRow.length != refLength) {
                 throw MathRuntimeException.createIllegalArgumentException(
@@ -861,7 +861,7 @@
     public RealMatrix getRowMatrix(final int row)
         throws MatrixIndexException {
 
-        checkRowIndex(row);
+        MatrixUtils.checkRowIndex(this, row);
         final DenseRealMatrix out = new DenseRealMatrix(1, columns);
 
         // perform copy block-wise, to ensure good cache behavior
@@ -914,7 +914,7 @@
     public void setRowMatrix(final int row, final DenseRealMatrix matrix)
         throws MatrixIndexException, InvalidMatrixException {
 
-        checkRowIndex(row);
+        MatrixUtils.checkRowIndex(this, row);
         final int nCols = getColumnDimension();
         if ((matrix.getRowDimension() != 1) ||
             (matrix.getColumnDimension() != nCols)) {
@@ -952,7 +952,7 @@
     public RealMatrix getColumnMatrix(final int column)
         throws MatrixIndexException {
 
-        checkColumnIndex(column);
+        MatrixUtils.checkColumnIndex(this, column);
         final DenseRealMatrix out = new DenseRealMatrix(rows, 1);
 
         // perform copy block-wise, to ensure good cache behavior
@@ -1003,7 +1003,7 @@
     void setColumnMatrix(final int column, final DenseRealMatrix matrix)
         throws MatrixIndexException, InvalidMatrixException {
 
-        checkColumnIndex(column);
+        MatrixUtils.checkColumnIndex(this, column);
         final int nRows = getRowDimension();
         if ((matrix.getRowDimension() != nRows) ||
             (matrix.getColumnDimension() != 1)) {
@@ -1039,7 +1039,7 @@
     public RealVector getRowVector(final int row)
         throws MatrixIndexException {
 
-        checkRowIndex(row);
+        MatrixUtils.checkRowIndex(this, row);
         final double[] outData = new double[columns];
 
         // perform copy block-wise, to ensure good cache behavior
@@ -1073,7 +1073,7 @@
     public RealVector getColumnVector(final int column)
         throws MatrixIndexException {
 
-        checkColumnIndex(column);
+        MatrixUtils.checkColumnIndex(this, column);
         final double[] outData = new double[rows];
 
         // perform copy block-wise, to ensure good cache behavior
@@ -1109,7 +1109,7 @@
     public double[] getRow(final int row)
         throws MatrixIndexException {
 
-        checkRowIndex(row);
+        MatrixUtils.checkRowIndex(this, row);
         final double[] out = new double[columns];
 
         // perform copy block-wise, to ensure good cache behavior
@@ -1132,7 +1132,7 @@
     public void setRow(final int row, final double[] array)
         throws MatrixIndexException, InvalidMatrixException {
 
-        checkRowIndex(row);
+        MatrixUtils.checkRowIndex(this, row);
         final int nCols = getColumnDimension();
         if (array.length != nCols) {
             throw new InvalidMatrixException(
@@ -1158,7 +1158,7 @@
     public double[] getColumn(final int column)
         throws MatrixIndexException {
 
-        checkColumnIndex(column);
+        MatrixUtils.checkColumnIndex(this, column);
         final double[] out = new double[rows];
 
         // perform copy block-wise, to ensure good cache behavior
@@ -1183,7 +1183,7 @@
     public void setColumn(final int column, final double[] array)
         throws MatrixIndexException, InvalidMatrixException {
 
-        checkColumnIndex(column);
+        MatrixUtils.checkColumnIndex(this, column);
         final int nRows = getRowDimension();
         if (array.length != nRows) {
             throw new InvalidMatrixException(
@@ -1467,7 +1467,7 @@
                                  final int startRow, final int endRow,
                                  final int startColumn, final int endColumn)
         throws MatrixIndexException, MatrixVisitorException {
-        checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
+        MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
         visitor.start(rows, columns, startRow, endRow, startColumn, endColumn);
         for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) {
             final int p0     = iBlock * BLOCK_SIZE;
@@ -1495,7 +1495,7 @@
                                  final int startRow, final int endRow,
                                  final int startColumn, final int endColumn)
         throws MatrixIndexException, MatrixVisitorException {
-        checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
+        MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
         visitor.start(rows, columns, startRow, endRow, startColumn, endColumn);
         for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) {
             final int p0     = iBlock * BLOCK_SIZE;
@@ -1567,7 +1567,7 @@
                                        final int startRow, final int endRow,
                                        final int startColumn, final int endColumn)
         throws MatrixIndexException, MatrixVisitorException {
-        checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
+        MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
         visitor.start(rows, columns, startRow, endRow, startColumn, endColumn);
         for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) {
             final int p0     = iBlock * BLOCK_SIZE;
@@ -1595,7 +1595,7 @@
                                        final int startRow, final int endRow,
                                        final int startColumn, final int endColumn)
         throws MatrixIndexException, MatrixVisitorException {
-        checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
+        MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
         visitor.start(rows, columns, startRow, endRow, startColumn, endColumn);
         for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) {
             final int p0     = iBlock * BLOCK_SIZE;

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/FieldMatrix.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/FieldMatrix.java?rev=772119&r1=772118&r2=772119&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/FieldMatrix.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/FieldMatrix.java Wed May  6 09:43:28 2009
@@ -32,7 +32,7 @@
  * @param <T> the type of the field elements
  * @version $Revision$ $Date$
  */
-public interface FieldMatrix<T extends FieldElement<T>> extends Serializable {
+public interface FieldMatrix<T extends FieldElement<T>> extends AnyMatrix, Serializable {
 
     /**
      * Get the type of field elements of the matrix.
@@ -432,26 +432,6 @@
     FieldMatrix<T> transpose();
 
     /**
-     * Is this a square matrix?
-     * @return true if the matrix is square (rowDimension = columnDimension)
-     */
-    boolean isSquare();
-
-    /**
-     * Returns the number of rows in the matrix.
-     *
-     * @return rowDimension
-     */
-    int getRowDimension();
-
-    /**
-     * Returns the number of columns in the matrix.
-     *
-     * @return columnDimension
-     */
-    int getColumnDimension();
-
-    /**
      * Returns the <a href="http://mathworld.wolfram.com/MatrixTrace.html">
      * trace</a> of the matrix (the sum of the elements on the main diagonal).
      *

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/MatrixUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/MatrixUtils.java?rev=772119&r1=772118&r2=772119&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/MatrixUtils.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/MatrixUtils.java Wed May  6 09:43:28 2009
@@ -491,6 +491,140 @@
         }
         return new BigMatrixImpl(data, false);
     }
+
+    /**
+     * Check if a row index is valid.
+     * @param m matrix containing the submatrix
+     * @param row row index to check
+     * @exception MatrixIndexException if index is not valid
+     */
+    public static void checkRowIndex(final AnyMatrix m, final int row) {
+        if (row < 0 || row >= m.getRowDimension()) {
+            throw new MatrixIndexException("row index {0} out of allowed range [{1}, {2}]",
+                                           row, 0, m.getRowDimension() - 1);
+        }
+    }
+
+    /**
+     * Check if a column index is valid.
+     * @param m matrix containing the submatrix
+     * @param column column index to check
+     * @exception MatrixIndexException if index is not valid
+     */
+    public static void checkColumnIndex(final AnyMatrix m, final int column)
+        throws MatrixIndexException {
+        if (column < 0 || column >= m.getColumnDimension()) {
+            throw new MatrixIndexException("column index {0} out of allowed range [{1}, {2}]",
+                                           column, 0, m.getColumnDimension() - 1);
+        }
+    }
+
+    /**
+     * Check if submatrix ranges indices are valid.
+     * Rows and columns are indicated counting from 0 to n-1.
+     *
+     * @param m matrix containing the submatrix
+     * @param startRow Initial row index
+     * @param endRow Final row index
+     * @param startColumn Initial column index
+     * @param endColumn Final column index
+     * @exception MatrixIndexException  if the indices are not valid
+     */
+    public static void checkSubMatrixIndex(final AnyMatrix m,
+                                           final int startRow, final int endRow,
+                                           final int startColumn, final int endColumn) {
+        checkRowIndex(m, startRow);
+        checkRowIndex(m, endRow);
+        if (startRow > endRow) {
+            throw new MatrixIndexException("initial row {0} after final row {1}",
+                                           startRow, endRow);
+        }
+
+        checkColumnIndex(m, startColumn);
+        checkColumnIndex(m, endColumn);
+        if (startColumn > endColumn) {
+            throw new MatrixIndexException("initial column {0} after final column {1}",
+                                           startColumn, endColumn);
+        }
+
     
-}
+    }
+
+    /**
+     * Check if submatrix ranges indices are valid.
+     * Rows and columns are indicated counting from 0 to n-1.
+     *
+     * @param m matrix containing the submatrix
+     * @param selectedRows Array of row indices.
+     * @param selectedColumns Array of column indices.
+     * @exception MatrixIndexException if row or column selections are not valid
+     */
+    public static void checkSubMatrixIndex(final AnyMatrix m,
+                                           final int[] selectedRows, final int[] selectedColumns)
+        throws MatrixIndexException {
+        if (selectedRows.length * selectedColumns.length == 0) {
+            if (selectedRows.length == 0) {
+                throw new MatrixIndexException("empty selected row index array");
+            }
+            throw new MatrixIndexException("empty selected column index array");
+        }
 
+        for (final int row : selectedRows) {
+            checkRowIndex(m, row);
+        }
+        for (final int column : selectedColumns) {
+            checkColumnIndex(m, column);
+        }
+    }
+
+    /**
+     * Check if matrices are addition compatible
+     * @param left left hand side matrix
+     * @param right right hand side matrix
+     * @exception IllegalArgumentException if matrices are not addition compatible
+     */
+    public static void checkAdditionCompatible(final AnyMatrix left, final AnyMatrix right)
+        throws IllegalArgumentException {
+        if ((left.getRowDimension()    != right.getRowDimension()) ||
+            (left.getColumnDimension() != right.getColumnDimension())) {
+            throw MathRuntimeException.createIllegalArgumentException(
+                    "{0}x{1} and {2}x{3} matrices are not addition compatible",
+                    left.getRowDimension(), left.getColumnDimension(),
+                    right.getRowDimension(), right.getColumnDimension());
+        }
+    }
+
+    /**
+     * Check if matrices are subtraction compatible
+     * @param left left hand side matrix
+     * @param right right hand side matrix
+     * @exception IllegalArgumentException if matrices are not subtraction compatible
+     */
+    public static void checkSubtractionCompatible(final AnyMatrix left, final AnyMatrix right)
+        throws IllegalArgumentException {
+        if ((left.getRowDimension()    != right.getRowDimension()) ||
+            (left.getColumnDimension() != right.getColumnDimension())) {
+            throw MathRuntimeException.createIllegalArgumentException(
+                    "{0}x{1} and {2}x{3} matrices are not subtraction compatible",
+                    left.getRowDimension(), left.getColumnDimension(),
+                    right.getRowDimension(), right.getColumnDimension());
+        }
+    }
+
+    /**
+     * Check if matrices are multiplication compatible
+     * @param left left hand side matrix
+     * @param right right hand side matrix
+     * @exception IllegalArgumentException if matrices are not multiplication compatible
+     */
+    public static void checkMultiplicationCompatible(final AnyMatrix left, final AnyMatrix right)
+        throws IllegalArgumentException {
+        if (left.getColumnDimension() != right.getRowDimension()) {
+            throw MathRuntimeException.createIllegalArgumentException(
+                    "{0}x{1} and {2}x{3} matrices are not multiplication compatible",
+                    left.getRowDimension(), left.getColumnDimension(),
+                    right.getRowDimension(), right.getColumnDimension());
+        }
+    }
+
+}

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealMatrix.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealMatrix.java?rev=772119&r1=772118&r2=772119&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealMatrix.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealMatrix.java Wed May  6 09:43:28 2009
@@ -31,7 +31,7 @@
  * 
  * @version $Revision$ $Date$
  */
-public interface RealMatrix extends Serializable {
+public interface RealMatrix extends AnyMatrix, Serializable {
 
     /**
      * Create a new RealMatrix of the same type as the instance with the supplied
@@ -460,12 +460,6 @@
     double getDeterminant();
 
     /**
-     * Is this a square matrix?
-     * @return true if the matrix is square (rowDimension = columnDimension)
-     */
-    boolean isSquare();
-
-    /**
      * Is this a singular matrix?
      * @return true if the matrix is singular
      * @deprecated as of release 2.0, replaced by the boolean negation of
@@ -475,20 +469,6 @@
     boolean isSingular();
 
     /**
-     * Returns the number of rows in the matrix.
-     *
-     * @return rowDimension
-     */
-    int getRowDimension();
-
-    /**
-     * Returns the number of columns in the matrix.
-     *
-     * @return columnDimension
-     */
-    int getColumnDimension();
-
-    /**
      * Returns the <a href="http://mathworld.wolfram.com/MatrixTrace.html">
      * trace</a> of the matrix (the sum of the elements on the main diagonal).
      *

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealMatrixImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealMatrixImpl.java?rev=772119&r1=772118&r2=772119&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealMatrixImpl.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealMatrixImpl.java Wed May  6 09:43:28 2009
@@ -188,7 +188,7 @@
         throws IllegalArgumentException {
 
         // safety check
-        checkAdditionCompatible(m);
+        MatrixUtils.checkAdditionCompatible(this, m);
 
         final int rowCount    = getRowDimension();
         final int columnCount = getColumnDimension();
@@ -228,7 +228,7 @@
         throws IllegalArgumentException {
 
         // safety check
-        checkSubtractionCompatible(m);
+        MatrixUtils.checkSubtractionCompatible(this, m);
 
         final int rowCount    = getRowDimension();
         final int columnCount = getColumnDimension();
@@ -268,7 +268,7 @@
         throws IllegalArgumentException {
 
         // safety check
-        checkMultiplicationCompatible(m);
+        MatrixUtils.checkMultiplicationCompatible(this, m);
 
         final int nRows = this.getRowDimension();
         final int nCols = m.getColumnDimension();
@@ -497,7 +497,7 @@
                                  final int startRow, final int endRow,
                                  final int startColumn, final int endColumn)
         throws MatrixIndexException, MatrixVisitorException {
-        checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
+        MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
         visitor.start(getRowDimension(), getColumnDimension(),
                       startRow, endRow, startColumn, endColumn);
         for (int i = startRow; i <= endRow; ++i) {
@@ -515,7 +515,7 @@
                                  final int startRow, final int endRow,
                                  final int startColumn, final int endColumn)
         throws MatrixIndexException, MatrixVisitorException {
-        checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
+        MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
         visitor.start(getRowDimension(), getColumnDimension(),
                       startRow, endRow, startColumn, endColumn);
         for (int i = startRow; i <= endRow; ++i) {
@@ -564,7 +564,7 @@
                                     final int startRow, final int endRow,
                                     final int startColumn, final int endColumn)
         throws MatrixIndexException, MatrixVisitorException {
-        checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
+        MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
         visitor.start(getRowDimension(), getColumnDimension(),
                       startRow, endRow, startColumn, endColumn);
         for (int j = startColumn; j <= endColumn; ++j) {
@@ -582,7 +582,7 @@
                                     final int startRow, final int endRow,
                                     final int startColumn, final int endColumn)
         throws MatrixIndexException, MatrixVisitorException {
-        checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
+        MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
         visitor.start(getRowDimension(), getColumnDimension(),
                       startRow, endRow, startColumn, endColumn);
         for (int j = startColumn; j <= endColumn; ++j) {

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealVectorFormat.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealVectorFormat.java?rev=772119&r1=772118&r2=772119&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealVectorFormat.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealVectorFormat.java Wed May  6 09:43:28 2009
@@ -245,7 +245,9 @@
             return format( (RealVector)obj, toAppendTo, pos);
         }
 
-        throw new IllegalArgumentException("Cannot format given Object as a RealVector");
+        throw MathRuntimeException.createIllegalArgumentException(
+              "cannot format a {0} instance as a real vector",
+              obj.getClass().getName());
 
     }
 

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseRealMatrix.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseRealMatrix.java?rev=772119&r1=772118&r2=772119&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseRealMatrix.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseRealMatrix.java Wed May  6 09:43:28 2009
@@ -101,7 +101,7 @@
     public RealMatrix add(SparseRealMatrix m) throws IllegalArgumentException {
 
         // safety check
-        checkAdditionCompatible(m);
+        MatrixUtils.checkAdditionCompatible(this, m);
 
         final RealMatrix out = new SparseRealMatrix(this);
         for (OpenIntToDoubleHashMap.Iterator iterator = m.entries.iterator(); iterator.hasNext();) {
@@ -136,7 +136,7 @@
     public RealMatrix subtract(SparseRealMatrix m) throws IllegalArgumentException {
 
         // safety check
-        checkAdditionCompatible(m);
+        MatrixUtils.checkAdditionCompatible(this, m);
 
         final RealMatrix out = new SparseRealMatrix(this);
         for (OpenIntToDoubleHashMap.Iterator iterator = m.entries.iterator(); iterator.hasNext();) {
@@ -159,7 +159,7 @@
         } catch (ClassCastException cce) {
 
             // safety check
-            checkMultiplicationCompatible(m);
+            MatrixUtils.checkMultiplicationCompatible(this, m);
 
             final int outCols = m.getColumnDimension();
             final DenseRealMatrix out = new DenseRealMatrix(rowDimension, outCols);
@@ -190,7 +190,7 @@
     public SparseRealMatrix multiply(SparseRealMatrix m) throws IllegalArgumentException {
 
         // safety check
-        checkMultiplicationCompatible(m);
+        MatrixUtils.checkMultiplicationCompatible(this, m);
 
         final int outCols = m.getColumnDimension();
         SparseRealMatrix out = new SparseRealMatrix(rowDimension, outCols);
@@ -222,8 +222,8 @@
     /** {@inheritDoc} */
     @Override
     public double getEntry(int row, int column) throws MatrixIndexException {
-        checkRowIndex(row);
-        checkColumnIndex(column);
+        MatrixUtils.checkRowIndex(this, row);
+        MatrixUtils.checkColumnIndex(this, column);
         return entries.get(computeKey(row, column));
     }
 
@@ -237,8 +237,8 @@
     @Override
     public void setEntry(int row, int column, double value)
             throws MatrixIndexException {
-        checkRowIndex(row);
-        checkColumnIndex(column);
+        MatrixUtils.checkRowIndex(this, row);
+        MatrixUtils.checkColumnIndex(this, column);
         if (value == 0.0) {
             entries.remove(computeKey(row, column));
         } else {
@@ -250,8 +250,8 @@
     @Override
     public void addToEntry(int row, int column, double increment)
             throws MatrixIndexException {
-        checkRowIndex(row);
-        checkColumnIndex(column);
+        MatrixUtils.checkRowIndex(this, row);
+        MatrixUtils.checkColumnIndex(this, column);
         final int key = computeKey(row, column);
         final double value = entries.get(key) + increment;
         if (value == 0.0) {
@@ -265,8 +265,8 @@
     @Override
     public void multiplyEntry(int row, int column, double factor)
             throws MatrixIndexException {
-        checkRowIndex(row);
-        checkColumnIndex(column);
+        MatrixUtils.checkRowIndex(this, row);
+        MatrixUtils.checkColumnIndex(this, column);
         final int key = computeKey(row, column);
         final double value = entries.get(key) * factor;
         if (value == 0.0) {

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ContinuousOutputModel.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ContinuousOutputModel.java?rev=772119&r1=772118&r2=772119&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ContinuousOutputModel.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ContinuousOutputModel.java Wed May  6 09:43:28 2009
@@ -115,11 +115,14 @@
     } else {
 
       if (getInterpolatedState().length != model.getInterpolatedState().length) {
-        throw new IllegalArgumentException("state vector dimension mismatch");
+          throw MathRuntimeException.createIllegalArgumentException(
+                "dimension mismatch {0} != {1}",
+                getInterpolatedState().length, model.getInterpolatedState().length);
       }
 
       if (forward ^ model.forward) {
-        throw new IllegalArgumentException("propagation direction mismatch");
+          throw MathRuntimeException.createIllegalArgumentException(
+                "propagation direction mismatch");
       }
 
       final StepInterpolator lastInterpolator = steps.get(index);
@@ -128,7 +131,8 @@
       final double step = current - previous;
       final double gap = model.getInitialTime() - current;
       if (Math.abs(gap) > 1.0e-3 * Math.abs(step)) {
-        throw new IllegalArgumentException("hole between time ranges");
+        throw MathRuntimeException.createIllegalArgumentException(
+              "{0} wide hole between models time ranges", Math.abs(gap));
       }
 
     }

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/NordsieckTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/NordsieckTransformer.java?rev=772119&r1=772118&r2=772119&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/NordsieckTransformer.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/NordsieckTransformer.java Wed May  6 09:43:28 2009
@@ -53,7 +53,9 @@
  * org.apache.commons.math.ode.nonstiff.AdamsBashforthIntegrator Adams-Bashforth}
  * integrator uses p=1, q=2, r=1, s=n. The {@link
  * org.apache.commons.math.ode.nonstiff.AdamsMoultonIntegrator Adams-Moulton}
- * integrator uses p=1, q=2, r=0, s=n-1.
+ * integrator uses p=1, q=2, r=0, s=n-1. The {@link
+ * org.apache.commons.math.ode.stiff.BDFIntegrator BDF} integrator uses p=1, q=n,
+ * r=0, s=1.
  * </p>
  * <p>
  * The Nordsieck form for a dimension n state history at step k is composed of the
@@ -81,6 +83,7 @@
  * @see org.apache.commons.math.ode.MultistepIntegrator
  * @see org.apache.commons.math.ode.nonstiff.AdamsBashforthIntegrator
  * @see org.apache.commons.math.ode.nonstiff.AdamsMoultonIntegrator
+ * @see org.apache.commons.math.ode.stiff.BDFIntegrator
  * @version $Revision$ $Date$
  * @since 2.0
  */

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/random/AbstractRandomGenerator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/random/AbstractRandomGenerator.java?rev=772119&r1=772118&r2=772119&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/random/AbstractRandomGenerator.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/random/AbstractRandomGenerator.java Wed May  6 09:43:28 2009
@@ -16,6 +16,8 @@
  */
 package org.apache.commons.math.random;
 
+import org.apache.commons.math.MathRuntimeException;
+
 /**
  * Abstract class implementing the {@link  RandomGenerator} interface.
  * Default implementations for all methods other than {@link #nextDouble()} and
@@ -138,7 +140,8 @@
      */
     public int nextInt(int n) {
         if (n <= 0 ) {
-            throw new IllegalArgumentException("upper bound must be positive");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "upper bound must be positive ({0})", n);
         }
         int result = (int) (nextDouble() * n);
         return result < n ? result : n - 1;

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java?rev=772119&r1=772118&r2=772119&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java Wed May  6 09:43:28 2009
@@ -228,8 +228,11 @@
                 double[] inputArray = (double[]) in;
                 return new ArrayDataAdapter(inputArray);
             } else {
-                throw new IllegalArgumentException(
-                    "Input data comes from the" + " unsupported source");
+                throw MathRuntimeException.createIllegalArgumentException(
+                      "input data comes from unsupported datasource: {0}, " +
+                      "supported sources: {1}, {2}",
+                      in.getClass().getName(),
+                      BufferedReader.class.getName(), double[].class.getName());
             }
         }
     }

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/random/RandomDataImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/random/RandomDataImpl.java?rev=772119&r1=772118&r2=772119&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/random/RandomDataImpl.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/random/RandomDataImpl.java Wed May  6 09:43:28 2009
@@ -24,6 +24,7 @@
 import java.security.NoSuchProviderException;
 import java.util.Collection;
 
+import org.apache.commons.math.MathRuntimeException;
 import org.apache.commons.math.util.MathUtils;
 
 /**
@@ -132,7 +133,8 @@
      */
     public String nextHexString(int len) {
         if (len <= 0) {
-            throw new IllegalArgumentException("length must be positive");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "length must be positive ({0})", len);
         }
 
         // Get a random number generator
@@ -177,8 +179,9 @@
      */
     public int nextInt(int lower, int upper) {
         if (lower >= upper) {
-            throw new IllegalArgumentException(
-                    "upper bound must be > lower bound");
+            throw MathRuntimeException.createIllegalArgumentException(
+                    "upper bound ({0}) must be greater than lower bound ({1})",
+                    upper, lower);
         }
         RandomGenerator rand = getRan();
         double r = rand.nextDouble();
@@ -197,8 +200,9 @@
      */
     public long nextLong(long lower, long upper) {
         if (lower >= upper) {
-            throw new IllegalArgumentException(
-                    "upper bound must be > lower bound");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "upper bound ({0}) must be greater than lower bound ({1})",
+                  upper, lower);
         }
         RandomGenerator rand = getRan();
         double r = rand.nextDouble();
@@ -227,7 +231,8 @@
      */
     public String nextSecureHexString(int len) {
         if (len <= 0) {
-            throw new IllegalArgumentException("length must be positive");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "length must be positive ({0})", len);
         }
 
         // Get SecureRandom and setup Digest provider
@@ -286,8 +291,9 @@
      */
     public int nextSecureInt(int lower, int upper) {
         if (lower >= upper) {
-            throw new IllegalArgumentException(
-                    "lower bound must be < upper bound");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "upper bound ({0}) must be greater than lower bound ({1})",
+                  upper, lower);
         }
         SecureRandom sec = getSecRan();
         return lower + (int) (sec.nextDouble() * (upper - lower + 1));
@@ -306,8 +312,9 @@
      */
     public long nextSecureLong(long lower, long upper) {
         if (lower >= upper) {
-            throw new IllegalArgumentException(
-                    "lower bound must be < upper bound");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "upper bound ({0}) must be greater than lower bound ({1})",
+                  upper, lower);
         }
         SecureRandom sec = getSecRan();
         return lower + (long) (sec.nextDouble() * (upper - lower + 1));
@@ -344,7 +351,8 @@
      */
     public long nextPoisson(double mean) {
         if (mean <= 0) {
-            throw new IllegalArgumentException("Poisson mean must be > 0");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "the Poisson mean must be positive ({0})", mean);
         }
 
         RandomGenerator rand = getRan();
@@ -446,7 +454,8 @@
      */
     public double nextGaussian(double mu, double sigma) {
         if (sigma <= 0) {
-            throw new IllegalArgumentException("Gaussian std dev must be > 0");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "standard deviation must be positive ({0})", sigma);
         }
         RandomGenerator rand = getRan();
         return sigma * rand.nextGaussian() + mu;
@@ -468,7 +477,8 @@
      */
     public double nextExponential(double mean) {
         if (mean < 0.0) {
-            throw new IllegalArgumentException("Exponential mean must be >= 0");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "mean must be positive ({0})", mean);
         }
         RandomGenerator rand = getRan();
         double unif = rand.nextDouble();
@@ -496,8 +506,9 @@
      */
     public double nextUniform(double lower, double upper) {
         if (lower >= upper) {
-            throw new IllegalArgumentException(
-                    "lower bound must be < upper bound");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "upper bound ({0}) must be greater than lower bound ({1})",
+                  upper, lower);
         }
         RandomGenerator rand = getRan();
 
@@ -655,10 +666,12 @@
      */
     public int[] nextPermutation(int n, int k) {
         if (k > n) {
-            throw new IllegalArgumentException("permutation k exceeds n");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "permutation k ({0}) exceeds n ({1})", k, n);
         }
         if (k == 0) {
-            throw new IllegalArgumentException("permutation k must be > 0");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "permutation k ({0}) must be positive", k);
         }
 
         int[] index = getNatural(n);
@@ -690,11 +703,12 @@
     public Object[] nextSample(Collection<?> c, int k) {
         int len = c.size();
         if (k > len) {
-            throw new IllegalArgumentException(
-                    "sample size exceeds collection size");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "sample size ({0}) exceeds collection size ({1})");
         }
-        if (k == 0) {
-            throw new IllegalArgumentException("sample size must be > 0");
+        if (k <= 0) {
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "sample size must be positive ({0})", k);
         }
 
         Object[] objects = c.toArray();
@@ -745,4 +759,5 @@
         }
         return natural;
     }
+
 }

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/random/UncorrelatedRandomVectorGenerator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/random/UncorrelatedRandomVectorGenerator.java?rev=772119&r1=772118&r2=772119&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/random/UncorrelatedRandomVectorGenerator.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/random/UncorrelatedRandomVectorGenerator.java Wed May  6 09:43:28 2009
@@ -19,6 +19,8 @@
 
 import java.util.Arrays;
 
+import org.apache.commons.math.MathRuntimeException;
+
 /** 
  * A {@link RandomVectorGenerator} that generates vectors with uncorrelated
  * components. Components of generated vectors follow (independent) Gaussian
@@ -46,7 +48,9 @@
                                            double[] standardDeviation,
                                            NormalizedRandomGenerator generator) {
     if (mean.length != standardDeviation.length) {
-      throw new IllegalArgumentException("dimension mismatch");
+      throw MathRuntimeException.createIllegalArgumentException(
+            "dimension mismatch {0} != {1}",
+            mean.length, standardDeviation.length);
     }
     this.mean              = mean.clone();
     this.standardDeviation = standardDeviation.clone();

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/stat/Frequency.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/Frequency.java?rev=772119&r1=772118&r2=772119&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/stat/Frequency.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/stat/Frequency.java Wed May  6 09:43:28 2009
@@ -22,6 +22,8 @@
 import java.util.Comparator;
 import java.util.TreeMap;
 
+import org.apache.commons.math.MathRuntimeException;
+
 /** 
  * Maintains a frequency distribution.
  * <p>
@@ -110,7 +112,9 @@
         if (v instanceof Comparable<?>){
             addValue((Comparable<?>) v);            
         } else {
-            throw new IllegalArgumentException("Object must implement Comparable");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "class ({0}) does not implement Comparable",
+                  v.getClass().getName());
         }
     }
     
@@ -138,7 +142,9 @@
             }
         } catch (ClassCastException ex) {   
             //TreeMap will throw ClassCastException if v is not comparable
-            throw new IllegalArgumentException("Value not comparable to existing values.");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "instance of class {0} not comparable to existing values",
+                  v.getClass().getName());
         }
     }
 

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/stat/StatUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/StatUtils.java?rev=772119&r1=772118&r2=772119&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/stat/StatUtils.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/stat/StatUtils.java Wed May  6 09:43:28 2009
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.math.stat;
 
+import org.apache.commons.math.MathRuntimeException;
 import org.apache.commons.math.stat.descriptive.UnivariateStatistic;
 import org.apache.commons.math.stat.descriptive.moment.GeometricMean;
 import org.apache.commons.math.stat.descriptive.moment.Mean;
@@ -563,9 +564,10 @@
     public static double sumDifference(final double[] sample1, final double[] sample2)
         throws IllegalArgumentException {
         int n = sample1.length;
-        if (n  != sample2.length || n < 1) {
-            throw new IllegalArgumentException 
-                ("Input arrays must have the same (positive) length.");
+        if ((n  != sample2.length) || (n < 1)) {
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "input arrays must have the same positive length ({0} and {1})",
+                  n, sample2.length);
         }
         double result = 0;
         for (int i = 0; i < n; i++) {
@@ -608,7 +610,9 @@
         double diff = 0d;
         int n = sample1.length;
         if (n < 2 || n != sample2.length) {
-            throw new IllegalArgumentException("Input array lengths must be equal and at least 2.");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "input arrays must have the same length and at least two elements ({0} and {1})",
+                  n, sample2.length);
         }
         for (int i = 0; i < n; i++) {
             diff = sample1[i] - sample2[i];

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/AbstractStorelessUnivariateStatistic.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/AbstractStorelessUnivariateStatistic.java?rev=772119&r1=772118&r2=772119&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/AbstractStorelessUnivariateStatistic.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/AbstractStorelessUnivariateStatistic.java Wed May  6 09:43:28 2009
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.math.stat.descriptive;
 
+import org.apache.commons.math.MathRuntimeException;
 import org.apache.commons.math.util.MathUtils;
 import java.io.Serializable;
 
@@ -58,7 +59,7 @@
     @Override
     public double evaluate(final double[] values) {
         if (values == null) {
-            throw new IllegalArgumentException("input value array is null");
+            throw MathRuntimeException.createIllegalArgumentException("input values array is null");
         }
         return evaluate(values, 0, values.length);
     }
@@ -126,7 +127,7 @@
      */
     public void incrementAll(double[] values) {
         if (values == null) {
-            throw new IllegalArgumentException("input values array is null");
+            throw MathRuntimeException.createIllegalArgumentException("input values array is null");
         }
         incrementAll(values, 0, values.length);
     } 

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatistic.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatistic.java?rev=772119&r1=772118&r2=772119&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatistic.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/AbstractUnivariateStatistic.java Wed May  6 09:43:28 2009
@@ -18,6 +18,8 @@
 
 import java.io.Serializable;
 
+import org.apache.commons.math.MathRuntimeException;
+
 /**
  * Abstract base class for all implementations of the 
  * {@link UnivariateStatistic} interface.
@@ -80,20 +82,22 @@
         final int length) {
 
         if (values == null) {
-            throw new IllegalArgumentException("input value array is null");
+            throw MathRuntimeException.createIllegalArgumentException("input values array is null");
         }
         
         if (begin < 0) {
-            throw new IllegalArgumentException("start position cannot be negative");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "start position cannot be negative ({0})", begin);
         }
         
         if (length < 0) {
-            throw new IllegalArgumentException("length cannot be negative");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "length cannot be negative ({0})", length);
         }
         
         if (begin + length > values.length) {
-            throw new IllegalArgumentException(
-                "begin + length > values.length");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "subarray ends after array end");
         }
 
         if (length == 0) {

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java?rev=772119&r1=772118&r2=772119&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/DescriptiveStatistics.java Wed May  6 09:43:28 2009
@@ -20,6 +20,7 @@
 import java.lang.reflect.InvocationTargetException;
 import java.util.Arrays;
 
+import org.apache.commons.math.MathRuntimeException;
 import org.apache.commons.math.stat.descriptive.moment.GeometricMean;
 import org.apache.commons.math.stat.descriptive.moment.Kurtosis;
 import org.apache.commons.math.stat.descriptive.moment.Mean;
@@ -301,7 +302,8 @@
     public void setWindowSize(int windowSize) {
         if (windowSize < 1) {
             if (windowSize != INFINITE_WINDOW) {
-                throw new IllegalArgumentException("window size must be positive.");
+                throw MathRuntimeException.createIllegalArgumentException(
+                      "window size must be positive ({0})", windowSize);
             }
         }
         
@@ -379,14 +381,15 @@
                         new Class[] {Double.TYPE}).invoke(percentileImpl,
                                 new Object[] {Double.valueOf(p)});
             } catch (NoSuchMethodException e1) { // Setter guard should prevent
-                throw new IllegalArgumentException(
-                   "Percentile implementation does not support setQuantile");
+                throw MathRuntimeException.createIllegalArgumentException(
+                      "percentile implementation {0} does not support setQuantile",
+                      percentileImpl.getClass().getName());
             } catch (IllegalAccessException e2) {
-                throw new IllegalArgumentException(
-                    "IllegalAccessException setting quantile"); 
+                throw MathRuntimeException.createIllegalArgumentException(
+                      "cannot access setQuantile method in percentile implementation {0}",
+                      percentileImpl.getClass().getName());
             } catch (InvocationTargetException e3) {
-                throw new IllegalArgumentException(
-                    "Error setting quantile" + e3.toString()); 
+                throw MathRuntimeException.createIllegalArgumentException(e3.getCause()); 
             }
         }
         return apply(percentileImpl);
@@ -561,14 +564,15 @@
                     new Class[] {Double.TYPE}).invoke(percentileImpl,
                             new Object[] {Double.valueOf(50.0d)});
         } catch (NoSuchMethodException e1) { 
-            throw new IllegalArgumentException(
-                    "Percentile implementation does not support setQuantile");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "percentile implementation {0} does not support setQuantile",
+                  percentileImpl.getClass().getName());
         } catch (IllegalAccessException e2) {
-            throw new IllegalArgumentException(
-                "IllegalAccessException setting quantile"); 
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "cannot access setQuantile method in percentile implementation {0}",
+                  percentileImpl.getClass().getName());
         } catch (InvocationTargetException e3) {
-            throw new IllegalArgumentException(
-                "Error setting quantile" + e3.toString()); 
+            throw MathRuntimeException.createIllegalArgumentException(e3.getCause()); 
         }
         this.percentileImpl = percentileImpl;
     }

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/Variance.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/Variance.java?rev=772119&r1=772118&r2=772119&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/Variance.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/Variance.java Wed May  6 09:43:28 2009
@@ -18,6 +18,7 @@
 
 import java.io.Serializable;
 
+import org.apache.commons.math.MathRuntimeException;
 import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic;
 
 /**
@@ -211,7 +212,7 @@
     @Override
     public double evaluate(final double[] values) {
         if (values == null) {
-            throw new IllegalArgumentException("input values array is null");
+            throw MathRuntimeException.createIllegalArgumentException("input values array is null");
         }
         return evaluate(values, 0, values.length);
     }

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java?rev=772119&r1=772118&r2=772119&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/rank/Percentile.java Wed May  6 09:43:28 2009
@@ -18,6 +18,8 @@
 
 import java.io.Serializable;
 import java.util.Arrays;
+
+import org.apache.commons.math.MathRuntimeException;
 import org.apache.commons.math.stat.descriptive.AbstractUnivariateStatistic;
 
 /**
@@ -196,7 +198,8 @@
         test(values, begin, length);
 
         if ((p > 100) || (p <= 0)) {
-            throw new IllegalArgumentException("invalid quantile value: " + p);
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "out of bounds quantile value: {0}, must be in (0, 100]", p);
         }
         if (length == 0) {
             return Double.NaN;
@@ -244,7 +247,8 @@
      */
     public void setQuantile(final double p) {
         if (p <= 0 || p > 100) {
-            throw new IllegalArgumentException("Illegal quantile value: " + p);
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "out of bounds quantile value: {0}, must be in (0, 100]", p);
         }
         quantile = p;
     }

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java?rev=772119&r1=772118&r2=772119&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/AbstractMultipleLinearRegression.java Wed May  6 09:43:28 2009
@@ -18,6 +18,8 @@
 
 import org.apache.commons.math.linear.RealMatrix;
 import org.apache.commons.math.linear.RealMatrixImpl;
+import org.apache.commons.math.linear.RealVector;
+import org.apache.commons.math.linear.RealVectorImpl;
 
 /**
  * Abstract base class for implementations of MultipleLinearRegression.
@@ -31,7 +33,7 @@
     protected RealMatrix X;
 
     /** Y sample data. */
-    protected RealMatrix Y;
+    protected RealVector Y;
 
     /**
      * Loads model x and y sample data from a flat array of data, overriding any previous sample.
@@ -39,7 +41,7 @@
      * 
      * @param data input data array
      * @param nobs number of observations (rows)
-     * @param nvars number of independent variables (columnns, not counting y)
+     * @param nvars number of independent variables (columns, not counting y)
      */
     public void newSampleData(double[] data, int nobs, int nvars) {
         double[] y = new double[nobs];
@@ -53,7 +55,7 @@
             }
         }
         this.X = new RealMatrixImpl(x);
-        this.Y = new RealMatrixImpl(y);
+        this.Y = new RealVectorImpl(y);
     }
     
     /**
@@ -62,7 +64,7 @@
      * @param y the [n,1] array representing the y sample
      */
     protected void newYSampleData(double[] y) {
-        this.Y = new RealMatrixImpl(y);
+        this.Y = new RealVectorImpl(y);
     }
 
     /**
@@ -120,17 +122,17 @@
      * {@inheritDoc}
      */
     public double[] estimateRegressionParameters() {
-        RealMatrix b = calculateBeta();
-        return b.getColumn(0);
+        RealVector b = calculateBeta();
+        return b.getData();
     }
 
     /**
      * {@inheritDoc}
      */
     public double[] estimateResiduals() {
-        RealMatrix b = calculateBeta();
-        RealMatrix e = Y.subtract(X.multiply(b));
-        return e.getColumn(0);
+        RealVector b = calculateBeta();
+        RealVector e = Y.subtract(X.operate(b));
+        return e.getData();
     }
 
     /**
@@ -166,7 +168,7 @@
      * 
      * @return beta
      */
-    protected abstract RealMatrix calculateBeta();
+    protected abstract RealVector calculateBeta();
 
     /**
      * Calculates the beta variance of multiple linear regression in matrix
@@ -193,9 +195,9 @@
      * 
      * @return The residuals [n,1] matrix
      */
-    protected RealMatrix calculateResiduals() {
-        RealMatrix b = calculateBeta();
-        return Y.subtract(X.multiply(b));
+    protected RealVector calculateResiduals() {
+        RealVector b = calculateBeta();
+        return Y.subtract(X.operate(b));
     }
 
 }

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java?rev=772119&r1=772118&r2=772119&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/stat/regression/SimpleRegression.java Wed May  6 09:43:28 2009
@@ -19,6 +19,7 @@
 import java.io.Serializable;
 
 import org.apache.commons.math.MathException;
+import org.apache.commons.math.MathRuntimeException;
 import org.apache.commons.math.distribution.TDistribution;
 import org.apache.commons.math.distribution.TDistributionImpl;
 
@@ -546,7 +547,9 @@
     public double getSlopeConfidenceInterval(double alpha)
         throws MathException {
         if (alpha >= 1 || alpha <= 0) {
-            throw new IllegalArgumentException();
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "out of bounds significance level {0}, must be in (0, 1)",
+                  alpha);
         }
         return getSlopeStdErr() *
             distribution.inverseCumulativeProbability(1d - alpha / 2d);

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java?rev=772119&r1=772118&r2=772119&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java Wed May  6 09:43:28 2009
@@ -176,14 +176,7 @@
      *         by a long integer.
      */
     public static long binomialCoefficient(final int n, final int k) {
-        if (n < k) {
-            throw new IllegalArgumentException(
-                "must have n >= k for binomial coefficient (n,k)");
-        }
-        if (n < 0) {
-            throw new IllegalArgumentException(
-                "must have n >= 0 for binomial coefficient (n,k)");
-        }
+        checkBinomial(n, k);
         if ((n == k) || (k == 0)) {
             return 1;
         }
@@ -253,14 +246,7 @@
      * @throws IllegalArgumentException if preconditions are not met.
      */
     public static double binomialCoefficientDouble(final int n, final int k) {
-        if (n < k) {
-            throw new IllegalArgumentException(
-                "must have n >= k for binomial coefficient (n,k)");
-        }
-        if (n < 0) {
-            throw new IllegalArgumentException(
-                "must have n >= 0 for binomial coefficient (n,k)");
-        }
+        checkBinomial(n, k);
         if ((n == k) || (k == 0)) {
             return 1d;
         }
@@ -301,14 +287,7 @@
      * @throws IllegalArgumentException if preconditions are not met.
      */
     public static double binomialCoefficientLog(final int n, final int k) {
-        if (n < k) {
-            throw new IllegalArgumentException(
-                "must have n >= k for binomial coefficient (n,k)");
-        }
-        if (n < 0) {
-            throw new IllegalArgumentException(
-                "must have n >= 0 for binomial coefficient (n,k)");
-        }
+        checkBinomial(n, k);
         if ((n == k) || (k == 0)) {
             return 0;
         }
@@ -353,6 +332,26 @@
 
         return logSum;      
     }
+
+    /**
+     * Check binomial preconditions.
+     * @param n the size of the set
+     * @param k the size of the subsets to be counted
+     * @exception IllegalArgumentException if preconditions are not met.
+     */
+    private static void checkBinomial(final int n, final int k)
+        throws IllegalArgumentException {
+        if (n < k) {
+            throw MathRuntimeException.createIllegalArgumentException(
+                "must have n >= k for binomial coefficient (n,k), got n = {0}, k = {1}",
+                n, k);
+        }
+        if (n < 0) {
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "must have n >= 0 for binomial coefficient (n,k), got n = {0}",
+                  n);
+        }
+    }
     
     /**
      * Compares two numbers given some amount of allowed error.
@@ -501,7 +500,9 @@
      */
     public static long factorial(final int n) {
         if (n < 0) {
-            throw new IllegalArgumentException("must have n >= 0 for n!");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "must have n >= 0 for n!, got n = {0}",
+                  n);
         }
         if (n > 20) {
             throw new ArithmeticException(
@@ -532,7 +533,9 @@
      */
     public static double factorialDouble(final int n) {
         if (n < 0) {
-            throw new IllegalArgumentException("must have n >= 0 for n!");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "must have n >= 0 for n!, got n = {0}",
+                  n);
         }
         if (n < 21) {
             return factorial(n);
@@ -555,7 +558,9 @@
      */
     public static double factorialLog(final int n) {
         if (n < 0) {
-            throw new IllegalArgumentException("must have n > 0 for n!");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "must have n >= 0 for n!, got n = {0}",
+                  n);
         }
         if (n < 21) {
             return Math.log(factorial(n));
@@ -1132,7 +1137,18 @@
             unscaled = Math.ceil(nextAfter(unscaled,  Double.POSITIVE_INFINITY));
             break;
         default :
-            throw new IllegalArgumentException("Invalid rounding method.");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "invalid rounding method {0}, valid methods: {1} ({2}), {3} ({4})," +
+                  " {5} ({6}), {7} ({8}), {9} ({10}), {11} ({12}), {13} ({14}), {15} ({16})",
+                  roundingMethod,
+                  "ROUND_CEILING",     BigDecimal.ROUND_CEILING,
+                  "ROUND_DOWN",        BigDecimal.ROUND_DOWN,
+                  "ROUND_FLOOR",       BigDecimal.ROUND_FLOOR,
+                  "ROUND_HALF_DOWN",   BigDecimal.ROUND_HALF_DOWN,
+                  "ROUND_HALF_EVEN",   BigDecimal.ROUND_HALF_EVEN,
+                  "ROUND_HALF_UP",     BigDecimal.ROUND_HALF_UP,
+                  "ROUND_UNNECESSARY", BigDecimal.ROUND_UNNECESSARY,
+                  "ROUND_UP",          BigDecimal.ROUND_UP);
         }
         return unscaled;
     }



Mime
View raw message