Fix "unary operator" warnings in FormulaManagerIT.

Okay, the reason the code included the unary plus was to more directly
represent the resulting expression, but I'm guessing the compiler isn't
going to respect that intent even if it could somehow understand it, so
it will probably remove the symbols and just parse it all the same.

Unlike with the unary plus, the unary minus can be "fixed" by wrapping
it in parentheses. The end result is of course the exact same, but the
intent is perhaps a bit clearer this way. We want to try to coerce the
compiler into creating an expression with "add a negative value", just
for the sake of "correctness" at the runtime evaluation level, but even
if that isn't what will actually happen, the explicit code is still a
bit easier to read. While unary plus is easy to disregard, "fixing" an
unnecessary unary minus would mean having to change the binary operator
before it, which muddies the intent of the expression.
This commit is contained in:
Andreas Troelsen 2024-01-01 17:49:21 +01:00
parent d8fdbb80c0
commit 82f00c5535
1 changed files with 4 additions and 4 deletions

View File

@ -230,8 +230,8 @@ public class FormulaManagerIT {
@Parameters(name = "{0} = {1}")
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
{"1 + +1.2", 1 + +1.2},
{"1 + -1.2", 1 + -1.2},
{"1 + +1.2", 1 + 1.2},
{"1 + -1.2", 1 + (-1.2)},
});
}
@ -259,8 +259,8 @@ public class FormulaManagerIT {
@Parameters(name = "{0} = {1}")
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
{"1+-2", 1 + -2},
{"3-+4", 3 - +4},
{"1+-2", 1 + (-2)},
{"3-+4", 3 - 4},
{"3*7.5", 3 * 7.5},
{"10/2.5", 10 / 2.5},
{"9%4", 9 % 4},