Skip to content

Commit 257aae6

Browse files
committed
Division by zero error
1 parent fac0245 commit 257aae6

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/nodes/eval/arithmetic.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,21 @@ std::unique_ptr<NodeResult> ArithmeticOperationNode::evaluate(PSC::Context &ctx)
101101
resNum = leftNum * rightNum;
102102
break;
103103
case TokenType::SLASH:
104+
if ((rightNum.real && ((PSC::Real&) rightNum).value == 0)
105+
|| (!rightNum.real && ((PSC::Integer&) rightNum).value == 0)
106+
) throw PSC::RuntimeError(token, ctx, "Division by 0");
104107
resNum = leftNum / rightNum;
105108
break;
106109
case TokenType::MOD:
110+
if ((rightNum.real && ((PSC::Real&) rightNum).value == 0)
111+
|| (!rightNum.real && ((PSC::Integer&) rightNum).value == 0)
112+
) throw PSC::RuntimeError(token, ctx, "Modulus by 0");
107113
resNum = leftNum % rightNum;
108114
break;
109115
case TokenType::DIV:
116+
if ((rightNum.real && ((PSC::Real&) rightNum).value == 0)
117+
|| (!rightNum.real && ((PSC::Integer&) rightNum).value == 0)
118+
) throw PSC::RuntimeError(token, ctx, "Division by 0");
110119
resNum = leftNum | rightNum;
111120
break;
112121
default:

0 commit comments

Comments
 (0)