Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 1BC64200C57 for ; Sat, 15 Apr 2017 18:33:54 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 1A3C6160BA0; Sat, 15 Apr 2017 16:33:54 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 3B59A160B8B for ; Sat, 15 Apr 2017 18:33:53 +0200 (CEST) Received: (qmail 94632 invoked by uid 500); 15 Apr 2017 16:33:47 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 94496 invoked by uid 99); 15 Apr 2017 16:33:47 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 15 Apr 2017 16:33:47 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2AD19DFB94; Sat, 15 Apr 2017 16:33:47 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: raydecampo@apache.org To: commits@commons.apache.org Date: Sat, 15 Apr 2017 16:33:47 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/2] commons-numbers git commit: Port ContinuedFraction from commons math. Converted exceptions to ArithmeticException. archived-at: Sat, 15 Apr 2017 16:33:54 -0000 Port ContinuedFraction from commons math. Converted exceptions to ArithmeticException. Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/44fa5ca2 Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/44fa5ca2 Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/44fa5ca2 Branch: refs/heads/feature-NUMBERS-12 Commit: 44fa5ca2be1b213b91465cc36d3b803dc68fed83 Parents: c4cae1c Author: Ray DeCampo Authored: Sat Apr 15 12:26:48 2017 -0400 Committer: Ray DeCampo Committed: Sat Apr 15 12:26:48 2017 -0400 ---------------------------------------------------------------------- .../numbers/fraction/ContinuedFraction.java | 37 +++++++++----------- .../numbers/fraction/ContinuedFractionTest.java | 3 +- 2 files changed, 17 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/44fa5ca2/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java ---------------------------------------------------------------------- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java index 56b7267..7608c2a 100644 --- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java @@ -14,11 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.commons.math4.util; +package org.apache.commons.numbers.fraction; -import org.apache.commons.math4.exception.ConvergenceException; -import org.apache.commons.math4.exception.MaxCountExceededException; -import org.apache.commons.math4.exception.util.LocalizedFormats; +import org.apache.commons.numbers.core.Precision; /** * Provides a generic means to evaluate continued fractions. Subclasses simply @@ -66,9 +64,9 @@ public abstract class ContinuedFraction { * Evaluates the continued fraction at the value x. * @param x the evaluation point. * @return the value of the continued fraction evaluated at x. - * @throws ConvergenceException if the algorithm fails to converge. + * @throws ArithmeticException if the algorithm fails to converge. */ - public double evaluate(double x) throws ConvergenceException { + public double evaluate(double x) { return evaluate(x, DEFAULT_EPSILON, Integer.MAX_VALUE); } @@ -77,9 +75,9 @@ public abstract class ContinuedFraction { * @param x the evaluation point. * @param epsilon maximum error allowed. * @return the value of the continued fraction evaluated at x. - * @throws ConvergenceException if the algorithm fails to converge. + * @throws ArithmeticException if the algorithm fails to converge. */ - public double evaluate(double x, double epsilon) throws ConvergenceException { + public double evaluate(double x, double epsilon) { return evaluate(x, epsilon, Integer.MAX_VALUE); } @@ -88,11 +86,10 @@ public abstract class ContinuedFraction { * @param x the evaluation point. * @param maxIterations maximum number of convergents * @return the value of the continued fraction evaluated at x. - * @throws ConvergenceException if the algorithm fails to converge. - * @throws MaxCountExceededException if maximal number of iterations is reached + * @throws ArithmeticException if the algorithm fails to converge. + * @throws ArithmeticException if maximal number of iterations is reached */ - public double evaluate(double x, int maxIterations) - throws ConvergenceException, MaxCountExceededException { + public double evaluate(double x, int maxIterations) { return evaluate(x, DEFAULT_EPSILON, maxIterations); } @@ -116,11 +113,10 @@ public abstract class ContinuedFraction { * @param epsilon maximum error allowed. * @param maxIterations maximum number of convergents * @return the value of the continued fraction evaluated at x. - * @throws ConvergenceException if the algorithm fails to converge. - * @throws MaxCountExceededException if maximal number of iterations is reached + * @throws ArithmeticException if the algorithm fails to converge. + * @throws ArithmeticException if maximal number of iterations is reached */ - public double evaluate(double x, double epsilon, int maxIterations) - throws ConvergenceException, MaxCountExceededException { + public double evaluate(double x, double epsilon, int maxIterations) { final double small = 1e-50; double hPrev = getA(0, x); @@ -152,15 +148,15 @@ public abstract class ContinuedFraction { hN = hPrev * deltaN; if (Double.isInfinite(hN)) { - throw new ConvergenceException(LocalizedFormats.CONTINUED_FRACTION_INFINITY_DIVERGENCE, + throw new FractionException("Continued fraction convergents diverged to +/- infinity for value {0}", x); } if (Double.isNaN(hN)) { - throw new ConvergenceException(LocalizedFormats.CONTINUED_FRACTION_NAN_DIVERGENCE, + throw new FractionException("Continued fraction diverged to NaN for value {0}", x); } - if (FastMath.abs(deltaN - 1.0) < epsilon) { + if (Math.abs(deltaN - 1.0) < epsilon) { break; } @@ -171,8 +167,7 @@ public abstract class ContinuedFraction { } if (n >= maxIterations) { - throw new MaxCountExceededException(LocalizedFormats.NON_CONVERGENT_CONTINUED_FRACTION, - maxIterations, x); + throw new FractionException("maximal count ({0}) exceeded", maxIterations); } return hN; http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/44fa5ca2/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/ContinuedFractionTest.java ---------------------------------------------------------------------- diff --git a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/ContinuedFractionTest.java b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/ContinuedFractionTest.java index 686fb51..f548fb1 100644 --- a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/ContinuedFractionTest.java +++ b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/ContinuedFractionTest.java @@ -14,9 +14,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.commons.math4.util; +package org.apache.commons.numbers.fraction; -import org.apache.commons.math4.util.ContinuedFraction; import org.junit.Assert; import org.junit.Test;