← All changes
|
libraries/vendor/PhpSpreadsheet/Calculation/Statistical/Distributions/Beta.php
+7
-2
3.3.2
→
3.4
View file →
| @@ -115,14 +115,19 @@ | ||
| 115 | 115 | } |
| 116 | 116 | if (($alpha <= 0) || ($beta <= 0) || ($rMin == $rMax) || ($probability <= 0.0)) { |
| 117 | 117 | return ExcelError::NAN(); |
| 118 | 118 | } |
| 119 | + if (($alpha + $beta) > self::LOG_GAMMA_X_MAX_VALUE) { | |
| 120 | + // incompleteBeta declines to evaluate here and returns 0 for every x, | |
| 121 | + // so there is no quantile to search for. | |
| 122 | + return ExcelError::NAN(); | |
| 123 | + } | |
| 119 | 124 | |
| 120 | 125 | return self::calculateInverse($probability, $alpha, $beta, $rMin, $rMax); |
| 121 | 126 | } |
| 122 | 127 | |
| 123 | 128 | /** |
| 124 | - * @return float|string | |
| 129 | + * @return string|float | |
| 125 | 130 | */ |
| 126 | 131 | private static function calculateInverse(float $probability, float $alpha, float $beta, float $rMin, float $rMax) |
| 127 | 132 | { |
| 128 | 133 | $a = 0; |
| @@ -132,9 +137,9 @@ | ||
| 132 | 137 | $i = 0; |
| 133 | 138 | while ((($b - $a) > Functions::PRECISION) && (++$i <= self::MAX_ITERATIONS)) { |
| 134 | 139 | $guess = ($a + $b) / 2; |
| 135 | 140 | $result = self::distribution($guess, $alpha, $beta); |
| 136 | - if (($result === $probability) || ($result === 0.0)) { | |
| 141 | + if ($result === $probability) { | |
| 137 | 142 | $b = $a; |
| 138 | 143 | } elseif ($result > $probability) { |
| 139 | 144 | $b = $guess; |
| 140 | 145 | } else { |