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.8: June, 2000
82
Copyright 1985, 1987, 2000 by Stephen L. Moshier
87
extern double lgam ( double );
88
extern double exp ( double );
89
extern double log ( double );
90
extern double fabs ( double );
91
extern double igam ( double, double );
92
extern double igamc ( double, double );
94
double lgam(), exp(), log(), fabs(), igam(), igamc();
97
extern double MACHEP, MAXLOG;
98
static double big = 4.503599627370496e15;
99
static double biginv = 2.22044604925031308085e-16;
104
double ans, ax, c, yc, r, t, y, z;
105
double pk, pkm1, pkm2, qk, qkm1, qkm2;
107
if( (x <= 0) || ( a <= 0) )
110
if( (x < 1.0) || (x < a) )
111
return( 1.0 - igam(a,x) );
113
ax = a * log(x) - x - lgam(a);
116
mtherr( "igamc", UNDERFLOW );
121
/* continued fraction */
137
pk = pkm1 * z - pkm2 * yc;
138
qk = qkm1 * z - qkm2 * yc;
142
t = fabs( (ans - r)/r );
166
/* left tail of incomplete gamma function:
179
double ans, ax, c, r;
181
if( (x <= 0) || ( a <= 0) )
184
if( (x > 1.0) && (x > a ) )
185
return( 1.0 - igamc(a,x) );
187
/* Compute x**a * exp(-x) / gamma(a) */
188
ax = a * log(x) - x - lgam(a);
191
mtherr( "igam", UNDERFLOW );
207
while( c/ans > MACHEP );
209
return( ans * ax/a );