commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1055929 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java
Date Thu, 06 Jan 2011 16:17:25 GMT
Author: erans
Date: Thu Jan  6 16:17:25 2011
New Revision: 1055929

URL: http://svn.apache.org/viewvc?rev=1055929&view=rev
Log:
MATH-468
Forgot to commit that file!

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java?rev=1055929&r1=1055928&r2=1055929&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java Thu
Jan  6 16:17:25 2011
@@ -35,6 +35,7 @@ import org.apache.commons.math.exception
 import org.apache.commons.math.exception.MathIllegalArgumentException;
 import org.apache.commons.math.exception.MathRuntimeException;
 import org.apache.commons.math.exception.NumberIsTooLargeException;
+import org.apache.commons.math.exception.NotFiniteNumberException;
 
 /**
  * Some useful additions to the built-in functions in {@link Math}.
@@ -1841,6 +1842,35 @@ public final class MathUtils {
     }
 
     /**
+     * Check that the argument is a real number.
+     *
+     * @param x Argument.
+     * @throws NotFiniteNumberException if {@code x} is not a
+     * finite real number.
+     */
+    public static void checkFinite(final double x) {
+        if (Double.isInfinite(x) || Double.isNaN(x)) {
+            throw new NotFiniteNumberException(x);
+        }
+    }
+
+    /**
+     * Check that all the elements are real number.
+     *
+     * @param val Arguments.
+     * @throws NotFiniteNumberException if any values of the array is not a
+     * finite real number.
+     */
+    public static void checkFinite(final double[] val) {
+        for (int i = 0; i < val.length; i++) {
+            final double x = val[i];
+            if (Double.isInfinite(x) || Double.isNaN(x)) {
+                throw new NotFiniteNumberException(LocalizedFormats.ARRAY_ELEMENT, x, i);
+            }
+        }
+    }
+
+    /**
      * Returns the Cartesian norm (2-norm), handling both overflow and underflow.
      * Translation of the minpack enorm subroutine.
      *



Mime
View raw message