diff --git a/util/src/main/java/tc/oc/pgm/util/math/Formula.java b/util/src/main/java/tc/oc/pgm/util/math/Formula.java index f96a26a2fb..ce04eee6df 100644 --- a/util/src/main/java/tc/oc/pgm/util/math/Formula.java +++ b/util/src/main/java/tc/oc/pgm/util/math/Formula.java @@ -29,6 +29,22 @@ public double apply(double... doubles) { } }; + Function MAX = + new Function("max", 2) { + @Override + public double apply(double... doubles) { + return Math.max(doubles[0], doubles[1]); + } + }; + + Function MIN = + new Function("min", 2) { + @Override + public double apply(double... doubles) { + return Math.min(doubles[0], doubles[1]); + } + }; + static >> Formula of( String expression, Set variables, Formula fallback) throws IllegalArgumentException { @@ -41,7 +57,10 @@ static Formula of(String expression, Set variables, ContextBuilde throws IllegalArgumentException { Expression exp = - new ExpressionBuilder(expression).variables(variables).functions(BOUND, RANDOM).build(); + new ExpressionBuilder(expression) + .variables(variables) + .functions(BOUND, RANDOM, MAX, MIN) + .build(); return new ExpFormula<>(exp, context); }