3
* Incomplete gamma integral
9
* double a, x, y, igam();
15
* The function is defined by
20
* igam(a,x) = ----- | e t dt.
26
* In this implementation both arguments must be positive.
27
* The integral is evaluated by either a power series or
28
* continued fraction expansion, depending on the relative
34
* arithmetic domain # trials peak rms
35
* IEEE 0,30 200000 3.6e-14 2.9e-15
36
* IEEE 0,100 300000 9.9e-14 1.5e-14
40
* Complemented incomplete gamma integral
46
* double a, x, y, igamc();
52
* The function is defined by
55
* igamc(a,x) = 1 - igam(a,x)
66
* In this implementation both arguments must be positive.
67
* The integral is evaluated by either a power series or
68
* continued fraction expansion, depending on the relative
73
* Tested at random a, x.
75
* arithmetic domain domain # trials peak rms
76
* IEEE 0.5,100 0,100 200000 1.9e-14 1.7e-15
77
* IEEE 0.01,0.5 0,100 200000 1.4e-13 1.6e-15
81
Cephes Math Library Release 2.0: April, 1987
82
Copyright 1985, 1987 by Stephen L. Moshier
83
Direct inquiries to 30 Frost Street, Cambridge, MA 02140
89
extern double MACHEP, MAXLOG;
90
static double big = 4.503599627370496e15;
91
static double biginv = 2.22044604925031308085e-16;
96
double ans, ax, c, yc, r, t, y, z;
97
double pk, pkm1, pkm2, qk, qkm1, qkm2;
99
if( (x <= 0) || ( a <= 0) )
102
if( (x < 1.0) || (x < a) )
103
return( 1.0 - igam(a,x) );
105
ax = a * log(x) - x - lgam(a);
108
mtherr( "igamc", UNDERFLOW );
113
/* continued fraction */
129
pk = pkm1 * z - pkm2 * yc;
130
qk = qkm1 * z - qkm2 * yc;
134
t = fabs( (ans - r)/r );
158
/* left tail of incomplete gamma function:
171
double ans, ax, c, r;
173
if( (x <= 0) || ( a <= 0) )
176
if( (x > 1.0) && (x > a ) )
177
return( 1.0 - igamc(a,x) );
179
/* Compute x**a * exp(-x) / gamma(a) */
180
ax = a * log(x) - x - lgam(a);
183
mtherr( "igam", UNDERFLOW );
199
while( c/ans > MACHEP );
201
return( ans * ax/a );