mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-24 01:00:05 +00:00
52da37f4a7
GAMMA.INV silently returned the first bisection midpoint for alpha in ~[143, 171.62] (e.g. GAMMA.INV(0.5, 143, 1) gave 358.0 instead of 142.667) and #NUM! above that, because the Newton-step pdf evaluates Gamma(a), b**a and value**(a-1) in linear domain, all of which overflow even though the density itself is a small representable number. The same pattern breaks the GAMMA.DIST, CHISQ.DIST and F.DIST densities and GAMMALN, which computed log(Gamma(x)) through Gamma(x). Evaluate these in log domain via the existing logGamma, and scale the incomplete-gamma series/continued-fraction iteration cap as O(sqrt(a)), which both expansions need to converge near x ~ a once the shape is large (GAMMA.INV drifted from the true quantile above alpha ~5000 and returned alpha+1 by alpha=10000; same for CHISQ.INV at high df).
48 lines
764 B
PHP
48 lines
764 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
return [
|
|
[
|
|
2.453736570842,
|
|
4.5,
|
|
],
|
|
[
|
|
1.791759469228,
|
|
4,
|
|
],
|
|
[
|
|
'#VALUE!',
|
|
'NAN',
|
|
],
|
|
'Value < 0' => [
|
|
'#NUM!',
|
|
-4.5,
|
|
],
|
|
'Value = 0' => [
|
|
'#NUM!',
|
|
0.0,
|
|
],
|
|
// Values beyond Gamma overflow (x > ~171.62); references from mpmath loggamma
|
|
'Value = 172' => [
|
|
711.714725802290,
|
|
172,
|
|
],
|
|
'Value = 200' => [
|
|
857.933669825857,
|
|
200,
|
|
],
|
|
'Value = 1000' => [
|
|
5905.220423209181,
|
|
1000,
|
|
],
|
|
'Value = 100000' => [
|
|
1051287.7089736569,
|
|
100000,
|
|
],
|
|
'lnGamma itself overflows a double' => [
|
|
'#NUM!',
|
|
1.0E+306,
|
|
],
|
|
];
|