mirror of
https://github.com/danog/endtoend-test-psl.git
synced 2024-11-29 20:29:52 +01:00
[Math] don't perform operations on possible numeric-string (#220)
This commit is contained in:
parent
46391a446c
commit
4895e61d6b
@ -9,7 +9,7 @@ use Psl\Iter;
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
@ -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;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ namespace Psl\Math;
|
||||
/**
|
||||
* Returns the float sum of the values of the given iterable.
|
||||
*
|
||||
* @param list<numeric> $numbers
|
||||
* @param list<int|float> $numbers
|
||||
*
|
||||
* @pure
|
||||
*/
|
||||
@ -15,8 +15,8 @@ function sum_floats(array $numbers): float
|
||||
{
|
||||
$result = 0.0;
|
||||
foreach ($numbers as $number) {
|
||||
$result += $number;
|
||||
$result += (float)$number;
|
||||
}
|
||||
|
||||
return (float) $result;
|
||||
return $result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user