Files
PhpSpreadsheet/tests/data/Calculation/Statistical/GAMMADIST.php
T
gaoflow e88cd615cc Fix incomplete gamma convergence for GAMMA.DIST / CHISQ.DIST
The incomplete gamma primitive used a fixed 32-term power series with no
convergence test, so GAMMA.DIST, GAMMADIST, CHISQ.DIST(.RT), GAMMAINV and
CHISQ.INV were grossly wrong once the series argument reached ~32
(e.g. CHISQ.DIST.RT(80, 4) returned 0.806 instead of 1.74e-16).

Replace it with the standard convergence-tested regularized incomplete
gamma: series P(a,x) for x < a+1, continued fraction Q(a,x) for x >= a+1.
CHISQ.DIST.RT now uses Q directly so the right tail stays free of
1 - P cancellation. Consolidates the duplicate copy that already existed
privately in ChiSquared onto the shared primitive.
2026-08-04 08:25:36 +02:00

76 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
return [
[
0.03263913041829,
10.00001131, 9, 2, false,
],
[
0.06809400387,
10.00001131, 9, 2, true,
],
[
0.112020903828,
6, 3, 2, false,
],
[
0.576809918873,
6, 3, 2, true,
],
'Boolean as numeric' => [
0.576809918873,
6, 3, 2, 1,
],
// Large x/b: the old fixed 32-term series diverged badly here.
'Large x mid-range' => [
0.522481190430,
35, 35, 1, true,
],
'Large x saturating' => [
1.0,
50, 2, 1, true,
],
[
1.0,
80, 2, 1, true,
],
[
'#VALUE!',
'NAN', 3, 2, true,
],
[
'#VALUE!',
6, 'NAN', 2, true,
],
[
'#VALUE!',
6, 3, 'NAN', true,
],
[
'#VALUE!',
6, 3, 2, 'NAN',
],
'Value < 0' => [
'#NUM!',
-6, 3, 2, true,
],
'A < 0' => [
'#NUM!',
6, -3, 2, true,
],
'A = 0' => [
'#NUM!',
6, 0, 2, true,
],
'B < 0' => [
'#NUM!',
6, 3, -2, true,
],
'B = 0' => [
'#NUM!',
6, 3, 0, true,
],
];