Class Evaluator
java.lang.Object
studio.magemonkey.codex.util.eval.Evaluator
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Evaluator
public Evaluator()
-
-
Method Details
-
eval
- Parameters:
exp- String math expression.method- Evaluation method. Allowed: 0 - internal, 1 - javaluator.- Returns:
- Evaluated expression.
-
compile
Parses a math expression once, so it can be evaluated many times with different values for its variables. Use this instead ofeval(String, int)when the same formula runs repeatedly.The syntax is that of the Javaluator evaluator (
+ - * / ^ %, unary minus, brackets,min,max,abs,sqrt, the constantspiandeand so on).- Parameters:
expression- the expression, such asmax(d / 5, d - 4 * x / max(1, t + 8))variables- the names of the variables the expression may use. Their values are later given toCompiledExpression.eval(double...)in this order. A name cannot be a function, a constant or a number, cannot contain an operator, bracket, comma or whitespace, and cannot be repeated.- Returns:
- the compiled expression, which is immutable and thread safe
- Throws:
IllegalArgumentException- with a message naming the expression, if it has a syntax error, mismatched brackets, an unknown variable or function, a function with the wrong number of arguments, or if a variable name is not usable
-