File indexing completed on 2024-04-06 12:01:12
0001 #include "CommonTools/Statistics/src/GammaSeries.h"
0002 #include <iostream>
0003 #include <cmath>
0004
0005 #define ITMAX 100
0006 #define EPS 3.0e-7
0007
0008 float GammaSeries(float a, float x) {
0009 if (x < 0.0)
0010 std::cerr << "GammaSeries::negative argument x" << std::endl;
0011
0012 if (x == 0.)
0013 return 0.;
0014
0015 if (a == 0.)
0016 return 0.;
0017
0018
0019
0020 double term = 1 / a;
0021 double sum = term;
0022 double aplus = a;
0023 for (int index = 1; index <= ITMAX; index++) {
0024 ++aplus;
0025 term *= x / aplus;
0026 sum += term;
0027 if (fabs(term) < fabs(sum) * EPS)
0028
0029 return sum;
0030 }
0031 std::cerr << "GammaSeries::a too large, ITMAX too small" << std::endl;
0032 return 0.;
0033 }