mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
Fix issue with precedence of % operator
This commit is contained in:
parent
bab6c8bddf
commit
2b671b8088
|
@ -28,6 +28,7 @@ public enum Precedence {
|
|||
COMPARISON,
|
||||
BITWISE_SHIFT,
|
||||
ADDITION,
|
||||
MODULO,
|
||||
MULTIPLICATION,
|
||||
UNARY,
|
||||
NEW,
|
||||
|
|
|
@ -561,7 +561,6 @@ public class StatementRenderer implements ExprVisitor, StatementVisitor {
|
|||
case SUBTRACT:
|
||||
case MULTIPLY:
|
||||
case DIVIDE:
|
||||
case MODULO:
|
||||
case AND:
|
||||
case OR:
|
||||
case BITWISE_AND:
|
||||
|
@ -610,8 +609,9 @@ public class StatementRenderer implements ExprVisitor, StatementVisitor {
|
|||
return Precedence.ADDITION;
|
||||
case MULTIPLY:
|
||||
case DIVIDE:
|
||||
case MODULO:
|
||||
return Precedence.MULTIPLICATION;
|
||||
case MODULO:
|
||||
return Precedence.MODULO;
|
||||
case AND:
|
||||
return Precedence.LOGICAL_AND;
|
||||
case OR:
|
||||
|
|
|
@ -496,7 +496,7 @@ public class VMTest {
|
|||
}
|
||||
|
||||
static class SuperClass {
|
||||
static final Integer ONE = new Integer(1);
|
||||
static final Integer ONE = Integer.valueOf(1);
|
||||
|
||||
private Integer value;
|
||||
|
||||
|
@ -617,4 +617,21 @@ public class VMTest {
|
|||
o = new int[0][];
|
||||
assertEquals(0, ((int[][]) o).length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void precedence() {
|
||||
float a = count(3);
|
||||
float b = count(7);
|
||||
float c = 5;
|
||||
assertEquals(1, a * b % c, 0.1f);
|
||||
assertEquals(6, a * (b % c), 0.1f);
|
||||
}
|
||||
|
||||
private int count(int value) {
|
||||
int result = 0;
|
||||
for (int i = 0; i < value; ++i) {
|
||||
result += 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user