diff --git a/src/PhpSpreadsheet/Calculation/Statistical.php b/src/PhpSpreadsheet/Calculation/Statistical.php index 52234f5a..6c1d6c7b 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical.php +++ b/src/PhpSpreadsheet/Calculation/Statistical.php @@ -765,14 +765,14 @@ class Statistical $rMax = Functions::flattenSingleValue($rMax); if ((is_numeric($value)) && (is_numeric($alpha)) && (is_numeric($beta)) && (is_numeric($rMin)) && (is_numeric($rMax))) { - if (($value < $rMin) || ($value > $rMax) || ($alpha <= 0) || ($beta <= 0) || ($rMin == $rMax)) { - return Functions::NAN(); - } if ($rMin > $rMax) { $tmp = $rMin; $rMin = $rMax; $rMax = $tmp; } + if (($value < $rMin) || ($value > $rMax) || ($alpha <= 0) || ($beta <= 0) || ($rMin == $rMax)) { + return Functions::NAN(); + } $value -= $rMin; $value /= ($rMax - $rMin); @@ -804,14 +804,14 @@ class Statistical $rMax = Functions::flattenSingleValue($rMax); if ((is_numeric($probability)) && (is_numeric($alpha)) && (is_numeric($beta)) && (is_numeric($rMin)) && (is_numeric($rMax))) { - if (($alpha <= 0) || ($beta <= 0) || ($rMin == $rMax) || ($probability <= 0) || ($probability > 1)) { - return Functions::NAN(); - } if ($rMin > $rMax) { $tmp = $rMin; $rMin = $rMax; $rMax = $tmp; } + if (($alpha <= 0) || ($beta <= 0) || ($rMin == $rMax) || ($probability <= 0) || ($probability > 1)) { + return Functions::NAN(); + } $a = 0; $b = 2; @@ -3000,11 +3000,11 @@ class Statistical public static function QUARTILE(...$args) { $aArgs = Functions::flattenArray($args); + $entry = array_pop($aArgs); // Calculate - $entry = floor(array_pop($aArgs)); - if ((is_numeric($entry)) && (!is_string($entry))) { + $entry = floor($entry); $entry /= 4; if (($entry < 0) || ($entry > 1)) { return Functions::NAN(); diff --git a/tests/data/Calculation/Statistical/BETADIST.php b/tests/data/Calculation/Statistical/BETADIST.php index f489429c..9fbecaaa 100644 --- a/tests/data/Calculation/Statistical/BETADIST.php +++ b/tests/data/Calculation/Statistical/BETADIST.php @@ -13,6 +13,10 @@ return [ 0.960370937542, 3, 7.5, 9, 1, 4, ], + [ + 0.960370937542, + 3, 7.5, 9, 4, 1, + ], [ 0.598190307617, 7.5, 8, 9, 5, 10, diff --git a/tests/data/Calculation/Statistical/BETAINV.php b/tests/data/Calculation/Statistical/BETAINV.php index d62c1c35..5afe14cb 100644 --- a/tests/data/Calculation/Statistical/BETAINV.php +++ b/tests/data/Calculation/Statistical/BETAINV.php @@ -9,6 +9,10 @@ return [ 2.164759759129, 0.3, 7.5, 9, 1, 4, ], + [ + 2.164759759129, + 0.3, 7.5, 9, 4, 1, + ], [ 7.761240188783, 0.75, 8, 9, 5, 10, diff --git a/tests/data/Calculation/Statistical/PERCENTILE.php b/tests/data/Calculation/Statistical/PERCENTILE.php index b5d60eca..121e49c0 100644 --- a/tests/data/Calculation/Statistical/PERCENTILE.php +++ b/tests/data/Calculation/Statistical/PERCENTILE.php @@ -25,4 +25,12 @@ return [ 48.4, [10.5, 7.2, 200, 5.4, 8.1, 0.8], ], + [ + '#NUM!', + [1, 2, 3, 4, -0.3], + ], + [ + '#VALUE!', + [1, 2, 3, 4, 'NaN'], + ], ]; diff --git a/tests/data/Calculation/Statistical/PERCENTRANK.php b/tests/data/Calculation/Statistical/PERCENTRANK.php index 86bf75f9..3ab019ac 100644 --- a/tests/data/Calculation/Statistical/PERCENTRANK.php +++ b/tests/data/Calculation/Statistical/PERCENTRANK.php @@ -49,4 +49,20 @@ return [ [13, 12, 11, 8, 4, 3, 2, 1, 1, 1], 5, ], + [ + 0.67, + [1, 'Deux', 2, 'Uno', 3, 4], + 3, + 2, + ], + [ + '#NUM!', + ['A', 'B', 'C', 'D'], + 'E', + ], + [ + '#N/A', + [1, 2, 3, 4], + 5, + ], ]; diff --git a/tests/data/Calculation/Statistical/QUARTILE.php b/tests/data/Calculation/Statistical/QUARTILE.php index f46ae97b..80b2bf09 100644 --- a/tests/data/Calculation/Statistical/QUARTILE.php +++ b/tests/data/Calculation/Statistical/QUARTILE.php @@ -37,4 +37,12 @@ return [ 9.25, [7, 8, 9, 10, 3], ], + [ + '#NUM!', + [7, 8, 9, 10, 5], + ], + [ + '#VALUE!', + [7, 8, 9, 10, 'X'], + ], ]; diff --git a/tests/data/Calculation/Statistical/RANK.php b/tests/data/Calculation/Statistical/RANK.php index b8f74e06..0640bb43 100644 --- a/tests/data/Calculation/Statistical/RANK.php +++ b/tests/data/Calculation/Statistical/RANK.php @@ -28,4 +28,14 @@ return [ 7.2, [10.5, 7.2, 200, 5.4, 8.1], ], + [ + 3, + 3.5, + [7, 3.5, 'ONE', 'UNO', 3.5, 1, 2], + ], + [ + '#N/A', + 1.5, + [7, 3.5, 3.5, 1, 2], + ], ];