Added min/max utility methods for RealField elements.
This commit is contained in:
parent
dbb04c1ccb
commit
c4e2ddf266
|
@ -19,6 +19,7 @@ package org.apache.commons.math4.util;
|
|||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.commons.math4.RealFieldElement;
|
||||
import org.apache.commons.math4.exception.MathArithmeticException;
|
||||
import org.apache.commons.math4.exception.NotFiniteNumberException;
|
||||
import org.apache.commons.math4.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>
|
||||
|
|
Loading…
Reference in New Issue