Class Expression
java.lang.Object
com.sk89q.worldedit.internal.expression.Expression
Compiles and evaluates expressions.
Supported operators:
- Logical: &&, ||, ! (unary)
- Bitwise: ~ (unary), >>, <<
- Arithmetic: +, -, *, /, % (modulo), ^ (power), - (unary), --, ++ (prefix only)
- Comparison: <=, >=, >, <, ==, !=, ~= (near)
Supported functions: abs, acos, asin, atan, atan2, cbrt, ceil, cos, cosh, exp, floor, ln, log, log10, max, max, min, min, rint, round, sin, sinh, sqrt, tan, tanh and more. (See the Functions class or the wiki)
Constants: e, pi
To compile an equation, run
Expression.compile("expression here", "var1", "var2"...)
.
If you wish to run the equation multiple times, you can then optimize it,
by calling optimize()
. You can then run the equation as many times
as you want by calling evaluate(double...)
. You do not need to
pass values for all slots specified while compiling.
To query slots after evaluation, you can use the slot table.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Expression
double
evaluate
(double... values) double
evaluate
(double[] values, int timeout) getSlots()
void
optimize()
void
setEnvironment
(ExpressionEnvironment environment) toString()
-
Method Details
-
compile
public static Expression compile(String expression, String... variableNames) throws ExpressionException - Throws:
ExpressionException
-
evaluate
- Throws:
EvaluationException
-
evaluate
- Throws:
EvaluationException
-
optimize
public void optimize() -
getSource
-
toString
-
getSlots
-
getEnvironment
-
setEnvironment
-