From ea333a0a63e8dbca8d4c1c9d0ea89a8f5667a1d0 Mon Sep 17 00:00:00 2001 From: Redstonneur1256 <29004178+Redstonneur1256@users.noreply.github.com> Date: Mon, 2 Jun 2025 20:05:45 +0200 Subject: [PATCH] True modulo and unsigned right shift. (#10885) --- core/assets/bundles/bundle.properties | 2 ++ core/src/mindustry/logic/LogicOp.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index a2098265a6..4fa00bd859 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -2599,11 +2599,13 @@ lenum.always = Always true. lenum.idiv = Integer division. lenum.div = Division.\nReturns [accent]null[] on divide-by-zero. lenum.mod = Modulo. +lenum.emod = True modulo, result is always positive. lenum.equal = Equal. Coerces types.\nNon-null objects compared with numbers become 1, otherwise 0. lenum.notequal = Not equal. Coerces types. lenum.strictequal = Strict equality. Does not coerce types.\nCan be used to check for [accent]null[]. lenum.shl = Bit-shift left. lenum.shr = Bit-shift right. +lenum.ushr = Unsigned bit-shift right. lenum.or = Bitwise OR. lenum.land = Logical AND. lenum.and = Bitwise AND. diff --git a/core/src/mindustry/logic/LogicOp.java b/core/src/mindustry/logic/LogicOp.java index 5cdc476209..e474bf68be 100644 --- a/core/src/mindustry/logic/LogicOp.java +++ b/core/src/mindustry/logic/LogicOp.java @@ -11,6 +11,7 @@ public enum LogicOp{ div("/", (a, b) -> a / b), idiv("//", (a, b) -> Math.floor(a / b)), mod("%", (a, b) -> a % b), + emod("%%", (a, b) -> ((a % b) + b) % b), pow("^", Math::pow), equal("==", (a, b) -> Math.abs(a - b) < 0.000001 ? 1 : 0, (a, b) -> Structs.eq(a, b) ? 1 : 0), @@ -24,6 +25,7 @@ public enum LogicOp{ shl("<<", (a, b) -> (long)a << (long)b), shr(">>", (a, b) -> (long)a >> (long)b), + ushr(">>>", (a, b) -> (long)a >>> (long)b), or("or", (a, b) -> (long)a | (long)b), and("b-and", (a, b) -> (long)a & (long)b), xor("xor", (a, b) -> (long)a ^ (long)b),