46 return std::tgamma(z);
59 if (a <= 0 || x <= 0)
return 0;
61 if (x < (a+1))
return GamSer(a,x);
62 else return GamCf(a,x);
66double MyGamma::GamCf(
double a,
double x)
78 double fpmin = 1.e-30;
80 if (a <= 0 || x <= 0)
return 0;
82 double gln = LnGamma(a);
88 for (
int i=1; i<=itmax; i++) {
89 an = double(-i)*(double(i)-a);
92 if (Abs(d) < fpmin) d = fpmin;
94 if (Abs(c) < fpmin) c = fpmin;
98 if (Abs(del-1) < eps)
break;
101 double v = Exp(-x+a*Log(x)-gln)*h;
106double MyGamma::GamSer(
double a,
double x)
119 if (a <= 0 || x <= 0)
return 0;
121 double gln = LnGamma(a);
125 for (
int n=1;
n<=itmax;
n++) {
129 if (MyGamma::Abs(del) < Abs(sum*eps))
break;
132 double v = sum*Exp(-x+a*Log(x)-gln);
137double MyGamma::LnGamma(
double z)
142 return std::lgamma(z);