Class CompiledExpression
java.lang.Object
studio.magemonkey.codex.util.eval.CompiledExpression
A math expression that was parsed once and can be evaluated many times with different variable values.
Get one from Evaluator.compile(String, String...):
CompiledExpression ce = Evaluator.compile("max(d / 5, d - 4 * x / max(1, t + 8))", "d", "x", "t");
double v = ce.eval(def, dmg, toughness);
The syntax, operators, functions and constants are those of the bundled Javaluator
DoubleEvaluator, and for any expression both accept the
result is the same double, bit for bit. The differences:
NaNand infinities are returned as they are.DoubleEvaluatorthrows when a function returns NaN (for examplesqrt(-1)); here that is the caller's check.random()gives a new random number on every call, as it does there.
-
Method Summary
Modifier and TypeMethodDescriptiondoubleeval(double... values) Evaluates the expression.The expression as it was given toEvaluator.compile(String, String...).The variable names, in the ordereval(double...)expects their values.toString()
-
Method Details
-
eval
public double eval(double... values) Evaluates the expression. Does not parse, does not allocate, and does not modifyvalues.- Parameters:
values- one value for each variable name, in the order the names were given tocompile- Returns:
- the result. May be NaN or infinite; checking is up to the caller.
- Throws:
IllegalArgumentException- if the number of values differs from the number of variable names
-
toString
-
getSource
The expression as it was given toEvaluator.compile(String, String...). -
getVariableNames
The variable names, in the ordereval(double...)expects their values. Unmodifiable.
-