Skip to content

Commit

Permalink
Added 'div by zero' check in BExpression.java DIV command
Browse files Browse the repository at this point in the history
  • Loading branch information
simdens committed Nov 7, 2023
1 parent 8f15385 commit 879371c
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public float evaluate(BExpressionContext ctx) {
case MULTIPLY_EXP:
return op1.evaluate(ctx) * op2.evaluate(ctx);
case DIV_EXP:
return op1.evaluate(ctx) / op2.evaluate(ctx);
return div(op1.evaluate(ctx), op2.evaluate(ctx));
case MAX_EXP:
return max(op1.evaluate(ctx), op2.evaluate(ctx));
case MIN_EXP:
Expand Down Expand Up @@ -365,6 +365,11 @@ private float min(float v1, float v2) {
return v1 < v2 ? v1 : v2;
}

private float div(float v1, float v2) {
if (v2 == 0f) throw new IllegalArgumentException("div by zero");
return v1 / v2;
}

@Override
public String toString() {
if (typ == NUMBER_EXP) {
Expand Down

0 comments on commit 879371c

Please sign in to comment.