Skip to content

Commit

Permalink
[BUGFIX] Support division by floats smaller than 1
Browse files Browse the repository at this point in the history
  • Loading branch information
s2b committed May 11, 2023
1 parent d43a22d commit cdf0b97
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected static function evaluateOperation($left, $operator, $right)
return $left * $right;
}
if ($operator === '/') {
return (int)$right !== 0 ? $left / $right : 0;
return is_int($right) && $right === 0 ? 0 : $left / $right;
}
if ($operator === '^') {
return pow($left, $right);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public static function getEvaluateExpressionTestValues(): array
['2 % 4', [], 2],
['2 * 4', [], 8],
['4 / 2', [], 2],
['4 / 0.5', [], 8],
['4 / 0', [], 0],
['4 ^ 2', [], 16],
['a + 1', ['a' => 1], 2],
['1 + b', ['b' => 1], 2],
Expand Down

0 comments on commit cdf0b97

Please sign in to comment.