[Math] don't perform operations on possible numeric-string (#220)

This commit is contained in:
orklah 2021-07-24 12:23:08 +02:00 committed by GitHub
parent 46391a446c
commit 4895e61d6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View File

@ -9,7 +9,7 @@ use Psl\Iter;
/** /**
* Return the arithmetic mean of the numbers in the given iterable. * 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 function mean(iterable $numbers): ?float
{ {
@ -20,8 +20,8 @@ function mean(iterable $numbers): ?float
$mean = 0.0; $mean = 0.0;
foreach ($numbers as $number) { foreach ($numbers as $number) {
$mean += $number / $count; $mean += (float)$number / $count;
} }
return (float) $mean; return $mean;
} }

View File

@ -7,7 +7,7 @@ namespace Psl\Math;
/** /**
* Returns the float sum of the values of the given iterable. * Returns the float sum of the values of the given iterable.
* *
* @param list<numeric> $numbers * @param list<int|float> $numbers
* *
* @pure * @pure
*/ */
@ -15,8 +15,8 @@ function sum_floats(array $numbers): float
{ {
$result = 0.0; $result = 0.0;
foreach ($numbers as $number) { foreach ($numbers as $number) {
$result += $number; $result += (float)$number;
} }
return (float) $result; return $result;
} }