Repository: commons-math
Updated Branches:
  refs/heads/field-ode 23f3ca423 -> 5f2459ded


Added min/max utility methods for RealField elements.

Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/5f2459de
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/5f2459de
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/5f2459de

Branch: refs/heads/field-ode
Commit: 5f2459ded2b51dc6fb1218531e99f62b528a6bde
Parents: 23f3ca4
Author: Luc Maisonobe <l...@apache.org>
Authored: Sun Nov 15 14:54:49 2015 +0100
Committer: Luc Maisonobe <l...@apache.org>
Committed: Sun Nov 15 14:54:49 2015 +0100

----------------------------------------------------------------------
 .../apache/commons/math3/util/MathUtils.java    | 23 ++++++++++++++++++++
 1 file changed, 23 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/5f2459de/src/main/java/org/apache/commons/math3/util/MathUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math3/util/MathUtils.java 
b/src/main/java/org/apache/commons/math3/util/MathUtils.java
index 0b5fc56..1ca9284 100644
--- a/src/main/java/org/apache/commons/math3/util/MathUtils.java
+++ b/src/main/java/org/apache/commons/math3/util/MathUtils.java
@@ -19,6 +19,7 @@ package org.apache.commons.math3.util;
 
 import java.util.Arrays;
 
+import org.apache.commons.math3.RealFieldElement;
 import org.apache.commons.math3.exception.MathArithmeticException;
 import org.apache.commons.math3.exception.NotFiniteNumberException;
 import org.apache.commons.math3.exception.NullArgumentException;
@@ -109,6 +110,28 @@ public final class MathUtils {
          return a - TWO_PI * FastMath.floor((a + FastMath.PI - center) / 
TWO_PI);
      }
 
+     /** Find the maximum of two field elements.
+      * @param <T> the type of the field elements
+      * @param e1 first element
+      * @param e2 second element
+      * @return max(a1, e2)
+      * @since 3.6
+      */
+     public static <T extends RealFieldElement<T>> T max(final T e1, final T 
e2) {
+         return e1.subtract(e2).getReal() >= 0 ? e1 : e2;
+     }
+
+     /** Find the minimum of two field elements.
+      * @param <T> the type of the field elements
+      * @param e1 first element
+      * @param e2 second element
+      * @return min(a1, e2)
+      * @since 3.6
+      */
+     public static <T extends RealFieldElement<T>> T min(final T e1, final T 
e2) {
+         return e1.subtract(e2).getReal() >= 0 ? e2 : e1;
+     }
+
     /**
      * <p>Reduce {@code |a - offset|} to the primary interval
      * {@code [0, |period|)}.</p>

Reply via email to