Skip to content

Commit b0ec180

Browse files
committed
Fix float associativity bug with addition
1 parent af44be8 commit b0ec180

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/org/jetbrains/java/decompiler/modules/decompiler/exps/FunctionExprent.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,10 @@ private TextBuffer wrapOperandString(Exprent expr, boolean eq, int indent, boole
737737
if (parentheses) {
738738
if (expr instanceof FunctionExprent &&
739739
((FunctionExprent)expr).getFuncType() == funcType) {
740-
parentheses = !ASSOCIATIVITY.contains(funcType);
740+
// Float operations are not assocative!
741+
if (expr.getExprType() != VarType.VARTYPE_FLOAT && expr.getExprType() != VarType.VARTYPE_DOUBLE) {
742+
parentheses = !ASSOCIATIVITY.contains(funcType);
743+
}
741744
}
742745
}
743746
}

test/org/jetbrains/java/decompiler/SingleClassesTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,6 @@ private void registerDefault() {
614614
// TODO: test2 now successfully triggers the bug in Vineflower
615615
register(JAVA_8, "TestTryVar");
616616
register(JAVA_8_NODEBUG, "TestTryVarNoDebug");
617-
// TODO: order of additions is wrong. Addition over floats isn't associative.
618-
// Derived from IDEA-291735
619617
register(JAVA_8, "TestFloatOrderOfOperations");
620618
// TODO: not simplifying to `+=`
621619
register(JAVA_8, "TestMixedCompoundAssignment");
@@ -651,7 +649,6 @@ private void registerDefault() {
651649
register(SCALA, "TestCompanionObject", "TestCompanionObject$");
652650
// TODO: foreach array index increment is added into default branch of switch statement
653651
register(JAVA_8, "TestForeachMultiDimensionalArray");
654-
// TODO: <unknown> value and cast, switch is eliminated, test2 contains entirely invalid code
655652
register(JAVA_17_PREVIEW, "TestUnknownCastJ17");
656653
// TODO: These variables shouldn't be merged, and should be split because each version is used once and has a different type use
657654
register(JAVA_8_NODEBUG, "TestVarIndex");

testData/results/pkg/TestFloatOrderOfOperations.dec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package pkg;
22

33
public class TestFloatOrderOfOperations {
44
public float test(float a, float b, float c) {
5-
return a + b + c;// 5
5+
return a + (b + c);// 5
66
}
77

88
public float testReference(float a, float b, float c) {
@@ -32,4 +32,4 @@ class 'pkg/TestFloatOrderOfOperations' {
3232

3333
Lines mapping:
3434
5 <-> 5
35-
9 <-> 9
35+
9 <-> 9

0 commit comments

Comments
 (0)