Skip to content

Commit 68d1473

Browse files
authored
Update to avoid cast when possible (#113)
1 parent da4bd2f commit 68d1473

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Expressions/UnaryExpression.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,17 @@ public function evaluateImpl(row $row, AsyncMysqlConnection $conn): mixed {
3030
invariant($op is nonnull, 'This case was not considered. The operator is null.');
3131
switch ($op) {
3232
case Operator::UNARY_MINUS:
33-
return -1 * (float)$val;
33+
// Keeping this cast around for backwards compat
34+
if (!($val is num)) {
35+
$val = (float)$val;
36+
}
37+
return -1 * $val;
3438
case Operator::UNARY_PLUS:
35-
return (float)$val;
39+
// Keeping this cast around for backwards compat
40+
if (!($val is num)) {
41+
$val = (float)$val;
42+
}
43+
return $val;
3644
case Operator::TILDE:
3745
return ~(int)$val;
3846
default:

0 commit comments

Comments
 (0)