Skip to content

Commit

Permalink
Division by zero error
Browse files Browse the repository at this point in the history
  • Loading branch information
SingularityT3 committed Apr 13, 2022
1 parent fac0245 commit 257aae6
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/nodes/eval/arithmetic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,21 @@ std::unique_ptr<NodeResult> ArithmeticOperationNode::evaluate(PSC::Context &ctx)
resNum = leftNum * rightNum;
break;
case TokenType::SLASH:
if ((rightNum.real && ((PSC::Real&) rightNum).value == 0)
|| (!rightNum.real && ((PSC::Integer&) rightNum).value == 0)
) throw PSC::RuntimeError(token, ctx, "Division by 0");
resNum = leftNum / rightNum;
break;
case TokenType::MOD:
if ((rightNum.real && ((PSC::Real&) rightNum).value == 0)
|| (!rightNum.real && ((PSC::Integer&) rightNum).value == 0)
) throw PSC::RuntimeError(token, ctx, "Modulus by 0");
resNum = leftNum % rightNum;
break;
case TokenType::DIV:
if ((rightNum.real && ((PSC::Real&) rightNum).value == 0)
|| (!rightNum.real && ((PSC::Integer&) rightNum).value == 0)
) throw PSC::RuntimeError(token, ctx, "Division by 0");
resNum = leftNum | rightNum;
break;
default:
Expand Down

0 comments on commit 257aae6

Please sign in to comment.