Skip to content

Commit

Permalink
[BUGFIX] Support division by floats smaller than 1
Browse files Browse the repository at this point in the history
Previously, divisions by a float smaller than 1 in Fluid inline syntax
always resulted in 0. This change adjusts MathExpressionNode
to differentiate between floats and integers correctly.

Resolves: #670
Resolves: https://forge.typo3.org/issues/99214
  • Loading branch information
s2b committed Jun 19, 2023
1 parent a502df3 commit b4fab77
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected static function evaluateOperation(int|float $left, ?string $operator,
return $left * $right;
}
if ($operator === '/') {
return (int)$right !== 0 ? $left / $right : 0;
return $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,14 @@ public static function getEvaluateExpressionTestValues(): array
['2 % 4', [], 2],
['2 * 4', [], 8],
['4 / 2', [], 2],
['4 / 0.5', [], 8],
['4 / 0', [], 0],
['4 / 0.0', [], 0],
['4 / b', ['b' => '0'], 0],
['4 / b', ['b' => 0.0], 0],
['4 / b', ['b' => '0.5'], 8],
['4 / b', ['b' => ''], 0],
['4 / b', ['b' => 'string input'], 0],
['4 ^ 2', [], 16],
['a + 1', ['a' => 1], 2],
['1 + b', ['b' => 1], 2],
Expand Down

0 comments on commit b4fab77

Please sign in to comment.