Skip to content

Commit c2f0bc8

Browse files
committed
fix: optimize bitwise operations and improve type handling in ExpressionParser
1 parent 3555874 commit c2f0bc8

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/main/java/mindustrytool/workflow/expressions/ExpressionParser.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,26 @@ public ExpressionParser() {
6565
registerNumber("Greater Than", ">", (a, b) -> a > b);
6666
registerNumber("Less Than or Equal", "<=", (a, b) -> a <= b);
6767
registerNumber("Greater Than or Equal", ">=", (a, b) -> a >= b);
68-
registerNumber("Bitwise AND", "and", (a, b) -> (double) (a.intValue() & b.intValue()));
69-
registerNumber("Bitwise OR", "or", (a, b) -> (double) (a.intValue() | b.intValue()));
70-
registerNumber("Bitwise XOR", "xor", (a, b) -> (double) (a.intValue() ^ b.intValue()));
71-
registerNumber("Left Shift", "<<", (a, b) -> (double) (a.intValue() << b.intValue()));
72-
registerNumber("Right Shift", ">>", (a, b) -> (double) (a.intValue() >> b.intValue()));
68+
registerNumber("Bitwise AND", "and", (a, b) -> (a.intValue() & b.intValue()));
69+
registerNumber("Bitwise OR", "or", (a, b) -> (a.intValue() | b.intValue()));
70+
registerNumber("Bitwise XOR", "xor", (a, b) -> (a.intValue() ^ b.intValue()));
71+
registerNumber("Left Shift", "<<", (a, b) -> (a.intValue() << b.intValue()));
72+
registerNumber("Right Shift", ">>", (a, b) -> (a.intValue() >> b.intValue()));
7373

7474
registerNumber("Absolute Value", "abs", Math::abs);
7575
registerNumber("Natural Logarithm", "log", Math::log);
7676
registerNumber("Base-10 Logarithm", "log10", Math::log10);
7777
registerNumber("Floor", "floor", Math::floor);
7878
registerNumber("Ceiling", "ceil", Math::ceil);
79-
registerNumber("Round", "round", a -> (double) Math.round(a));
79+
registerNumber("Round", "round", a -> Math.round(a));
8080
registerNumber("Square Root", "sqrt", Math::sqrt);
8181
registerNumber("Sine", "sin", Math::sin);
8282
registerNumber("Cosine", "cos", Math::cos);
8383
registerNumber("Tangent", "tan", Math::tan);
8484
registerNumber("Arcsine", "asin", Math::asin);
8585
registerNumber("Arccosine", "acos", Math::acos);
8686
registerNumber("Arctangent", "atan", Math::atan);
87-
registerNumber("Bitwise NOT", "flip", a -> (double) ~(a.intValue()));
87+
registerNumber("Bitwise NOT", "flip", a -> ~(a.intValue()));
8888
registerNumber("Square", "square", a -> a * a);
8989
registerNumber("Length (abs)", "length", a -> Math.abs(a));
9090

@@ -206,8 +206,8 @@ public <T> T evaluate(Class<T> type, String expr, Map<String, Object> variables)
206206
token = token.trim();
207207

208208
if (BINARY_OPERATORS.containsKey(token)) {
209-
double b = (double) stack.pop();
210-
double a = (double) stack.pop();
209+
Double b = (Double) stack.pop();
210+
Double a = (Double) stack.pop();
211211
var operation = BINARY_OPERATORS.get(token);
212212
try {
213213
var result = operation.getFunction().apply(a, b);
@@ -217,7 +217,7 @@ public <T> T evaluate(Class<T> type, String expr, Map<String, Object> variables)
217217
throw new WorkflowError("Invalid unary operation: " + a + " " + operation.getSign() + " " + b, e);
218218
}
219219
} else if (UNARY_OPERATORS.containsKey(token)) {
220-
double a = (double) stack.pop();
220+
Double a = (Double) stack.pop();
221221
var operation = UNARY_OPERATORS.get(token);
222222
try {
223223
var result = operation.getFunction().apply(a);

0 commit comments

Comments
 (0)