From 4895e61d6b04b313bb9459c6927c8071535bbdf9 Mon Sep 17 00:00:00 2001 From: orklah Date: Sat, 24 Jul 2021 12:23:08 +0200 Subject: [PATCH] [Math] don't perform operations on possible numeric-string (#220) --- src/Psl/Math/mean.php | 6 +++--- src/Psl/Math/sum_floats.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Psl/Math/mean.php b/src/Psl/Math/mean.php index 712bc48..7e9e283 100644 --- a/src/Psl/Math/mean.php +++ b/src/Psl/Math/mean.php @@ -9,7 +9,7 @@ use Psl\Iter; /** * Return the arithmetic mean of the numbers in the given iterable. * - * @param iterable $numbers + * @param iterable $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; } diff --git a/src/Psl/Math/sum_floats.php b/src/Psl/Math/sum_floats.php index c72651a..51fb4fa 100644 --- a/src/Psl/Math/sum_floats.php +++ b/src/Psl/Math/sum_floats.php @@ -7,7 +7,7 @@ namespace Psl\Math; /** * Returns the float sum of the values of the given iterable. * - * @param list $numbers + * @param list $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; }