Skip to content

Commit

Permalink
fix: bcadd(): Argument is not well-formed
Browse files Browse the repository at this point in the history
  • Loading branch information
rskrzypczak committed Mar 6, 2025
1 parent de6cfd8 commit f02ab28
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/Math.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,17 @@ public static function add(string ...$numbers)
{
if (!isset($numbers[2])) {
// % is not fully supported, so if % appears here for some reason, it is removed.
if(!is_numeric($numbers[0])) {
$numbers[0] = (string) (float) $numbers[0];
}
return bcadd($numbers[0], $numbers[1], static::$scale);
return bcadd(
is_numeric($numbers[0]) ? $numbers[0] : ((string) (float) $numbers[0]),
is_numeric($numbers[1]) ? $numbers[1] : ((string) (float) $numbers[1]),
static::$scale
);
}
$result = '0';
foreach ($numbers as $number) {
$result = bcadd($result, $number, static::$scale);
$result = bcadd($result, is_numeric($number) ? $number : ((string) (float) $number), static::$scale);
}

return $result;
}

Expand Down

0 comments on commit f02ab28

Please sign in to comment.