From 925305f0fa55126cb59b0eae4468bedcb66dc16c Mon Sep 17 00:00:00 2001 From: Luc Maisonobe Date: Fri, 16 Oct 2009 07:12:56 +0000 Subject: [PATCH] removed a Math.min computation that could be avoided improved javadoc git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@825784 13f79535-47bb-0310-9956-ffa450edef68 --- .../PolynomialFunctionLagrangeForm.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionLagrangeForm.java b/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionLagrangeForm.java index 28593706b..986d375d1 100644 --- a/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionLagrangeForm.java +++ b/src/main/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionLagrangeForm.java @@ -274,8 +274,13 @@ public class PolynomialFunctionLagrangeForm implements UnivariateRealFunction { /** * Verifies that the interpolation arrays are valid. *

+ * The arrays features checked by this method are that both arrays have the + * same length and this length is at least 2. + *

+ *

* The interpolating points must be distinct. However it is not - * verified here, it is checked in evaluate() and computeCoefficients().

+ * verified here, it is checked in evaluate() and computeCoefficients(). + *

* * @param x the interpolating points array * @param y the interpolating values array @@ -283,17 +288,18 @@ public class PolynomialFunctionLagrangeForm implements UnivariateRealFunction { * @see #evaluate(double[], double[], double) * @see #computeCoefficients() */ - public static void verifyInterpolationArray(double x[], double y[]) throws - IllegalArgumentException { + public static void verifyInterpolationArray(double x[], double y[]) + throws IllegalArgumentException { - if (Math.min(x.length, y.length) < 2) { - throw MathRuntimeException.createIllegalArgumentException( - "{0} points are required, got only {1}", - 2, Math.min(x.length, y.length)); - } if (x.length != y.length) { throw MathRuntimeException.createIllegalArgumentException( "dimension mismatch {0} != {1}", x.length, y.length); } + + if (x.length < 2) { + throw MathRuntimeException.createIllegalArgumentException( + "{0} points are required, got only {1}", 2, x.length); + } + } }