Skip to content

Commit

Permalink
[Math] don't perform operations on possible numeric-string (azjezz#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
orklah committed Jul 24, 2021
1 parent 46391a4 commit 4895e61
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/Psl/Math/mean.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* Return the arithmetic mean of the numbers in the given iterable.
*
* @param iterable<numeric> $numbers
* @param iterable<int|float> $numbers
*/
function mean(iterable $numbers): ?float
{
Expand All @@ -20,8 +20,8 @@ function mean(iterable $numbers): ?float

$mean = 0.0;
foreach ($numbers as $number) {
$mean += $number / $count;
$mean += (float)$number / $count;
}

return (float) $mean;
return $mean;
}
6 changes: 3 additions & 3 deletions src/Psl/Math/sum_floats.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
/**
* Returns the float sum of the values of the given iterable.
*
* @param list<numeric> $numbers
* @param list<int|float> $numbers
*
* @pure
*/
function sum_floats(array $numbers): float
{
$result = 0.0;
foreach ($numbers as $number) {
$result += $number;
$result += (float)$number;
}

return (float) $result;
return $result;
}

0 comments on commit 4895e61

Please sign in to comment.