You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by lu...@apache.org on 2007/02/12 20:17:42 UTC
svn commit: r506585 [2/2] - in /jakarta/commons/proper/math/trunk/src:
java/org/apache/commons/math/ java/org/apache/commons/math/analysis/
java/org/apache/commons/math/special/ java/org/apache/commons/math/util/
test/org/apache/commons/math/
Modified: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/TrapezoidIntegrator.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/TrapezoidIntegrator.java?view=diff&rev=506585&r1=506584&r2=506585
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/TrapezoidIntegrator.java (original)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/TrapezoidIntegrator.java Mon Feb 12 11:17:41 2007
@@ -16,8 +16,8 @@
*/
package org.apache.commons.math.analysis;
-import org.apache.commons.math.ConvergenceException;
import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.MaxIterationsExceededException;
/**
* Implements the <a href="http://mathworld.wolfram.com/TrapezoidalRule.html">
@@ -32,7 +32,7 @@
public class TrapezoidIntegrator extends UnivariateRealIntegratorImpl {
/** serializable version identifier */
- static final long serialVersionUID = 4978222553983172543L;
+ private static final long serialVersionUID = 4978222553983172543L;
/** intermediate result */
private double s;
@@ -91,13 +91,13 @@
* @param min the lower bound for the interval
* @param max the upper bound for the interval
* @return the value of integral
- * @throws ConvergenceException if the maximum iteration count is exceeded
+ * @throws MaxIterationsExceededException if the maximum iteration count is exceeded
* or the integrator detects convergence problems otherwise
* @throws FunctionEvaluationException if an error occurs evaluating the
* function
* @throws IllegalArgumentException if any parameters are invalid
*/
- public double integrate(double min, double max) throws ConvergenceException,
+ public double integrate(double min, double max) throws MaxIterationsExceededException,
FunctionEvaluationException, IllegalArgumentException {
int i = 1;
@@ -119,7 +119,7 @@
oldt = t;
i++;
}
- throw new ConvergenceException("Maximum number of iterations exceeded.");
+ throw new MaxIterationsExceededException(maximalIterationCount);
}
/**
Modified: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/special/Gamma.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/special/Gamma.java?view=diff&rev=506585&r1=506584&r2=506585
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/special/Gamma.java (original)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/special/Gamma.java Mon Feb 12 11:17:41 2007
@@ -18,8 +18,8 @@
import java.io.Serializable;
-import org.apache.commons.math.ConvergenceException;
import org.apache.commons.math.MathException;
+import org.apache.commons.math.MaxIterationsExceededException;
import org.apache.commons.math.util.ContinuedFraction;
/**
@@ -30,6 +30,9 @@
*/
public class Gamma implements Serializable {
+ /** Serializable version identifier */
+ private static final long serialVersionUID = -6587513359895466954L;
+
/** Maximum allowed numerical error. */
private static final double DEFAULT_EPSILON = 10e-9;
@@ -174,8 +177,7 @@
sum = sum + an;
}
if (n >= maxIterations) {
- throw new ConvergenceException(
- "maximum number of iterations reached");
+ throw new MaxIterationsExceededException(maxIterations);
} else {
ret = Math.exp(-x + (a * Math.log(x)) - logGamma(a)) * sum;
}
@@ -239,6 +241,9 @@
} else {
// create continued fraction
ContinuedFraction cf = new ContinuedFraction() {
+
+ private static final long serialVersionUID = 5378525034886164398L;
+
protected double getA(int n, double x) {
return ((2.0 * n) + 1.0) - a + x;
}
Modified: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/util/ContinuedFraction.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/util/ContinuedFraction.java?view=diff&rev=506585&r1=506584&r2=506585
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/util/ContinuedFraction.java (original)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/util/ContinuedFraction.java Mon Feb 12 11:17:41 2007
@@ -20,6 +20,7 @@
import org.apache.commons.math.ConvergenceException;
import org.apache.commons.math.MathException;
+import org.apache.commons.math.MaxIterationsExceededException;
/**
* Provides a generic means to evaluate continued fractions. Subclasses simply
@@ -153,8 +154,8 @@
} else {
// can not scale an convergent is unbounded.
throw new ConvergenceException(
- "Continued fraction convergents diverged to +/- " +
- "infinity.");
+ "Continued fraction convergents diverged to +/- infinity for value {0}",
+ new Object[] { new Double(x) });
}
}
double r = p2 / q2;
@@ -169,8 +170,9 @@
}
if (n >= maxIterations) {
- throw new ConvergenceException(
- "Continued fraction convergents failed to converge.");
+ throw new MaxIterationsExceededException(maxIterations,
+ "Continued fraction convergents failed to converge for value {0}",
+ new Object[] { new Double(x) });
}
return c;
Added: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/MaxIterationsExceededExceptionTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/MaxIterationsExceededExceptionTest.java?view=auto&rev=506585
==============================================================================
--- jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/MaxIterationsExceededExceptionTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/MaxIterationsExceededExceptionTest.java Mon Feb 12 11:17:41 2007
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.commons.math;
+
+import java.util.Locale;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Revision:$
+ */
+public class MaxIterationsExceededExceptionTest extends TestCase {
+
+ public void testConstructor(){
+ MaxIterationsExceededException ex = new MaxIterationsExceededException(1000000);
+ assertNull(ex.getCause());
+ assertNotNull(ex.getMessage());
+ assertTrue(ex.getMessage().indexOf("1,000,000") > 0);
+ assertEquals(1000000, ex.getMaxIterations());
+ assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
+ }
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/MaxIterationsExceededExceptionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org