Go to the documentation of this file.00001 #include "CommonTools/Statistics/src/GammaSeries.h"
00002 #include <iostream>
00003 #include <cmath>
00004
00005 #define ITMAX 100 // maximum allowed number of iterations
00006 #define EPS 3.0e-7 // relative accuracy
00007
00008 float GammaSeries( float a, float x )
00009 {
00010 if( x < 0.0 )
00011 std::cerr << "GammaSeries::negative argument x" << std::endl;
00012
00013 if( x == 0. )
00014 return 0.;
00015
00016
00017
00018 double term = 1/a;
00019 double sum = term;
00020 double aplus = a;
00021 for( int index = 1; index <= ITMAX; index++) {
00022 ++aplus;
00023 term *= x/aplus;
00024 sum += term;
00025 if( fabs(term) < fabs(sum)*EPS )
00026
00027 return sum;
00028 }
00029 std::cerr << "GammaSeries::a too large, ITMAX too small" << std::endl;
00030 return 0.;
00031 }
00032