00001 // $Id:$ 00002 // -*- C++ -*- 00003 // 00004 // ----------------------------------------------------------------------- 00005 // HEP Random 00006 // --- HepStat::gammln --- 00007 // method implementation file 00008 // ----------------------------------------------------------------------- 00009 00010 // ======================================================================= 00011 // M. Fischler - moved the gammln from RandPoisson to here. 01/26/00 00012 // ======================================================================= 00013 00014 #include "CLHEP/Random/Stat.h" 00015 #include <cmath> 00016 00017 namespace CLHEP { 00018 00019 double HepStat::gammln(double xx) { 00020 00021 // Returns the value ln(Gamma(xx) for xx > 0. Full accuracy is obtained for 00022 // xx > 1. For 0 < xx < 1. the reflection formula (6.1.4) can be used first. 00023 // (Adapted from Numerical Recipes in C. Relative to that routine, this 00024 // subtracts one from x at the very start, and in exchange does not have to 00025 // divide ser by x at the end. The results are formally equal, and practically 00026 // indistinguishable.) 00027 00028 static double cof[6] = {76.18009172947146,-86.50532032941677, 00029 24.01409824083091, -1.231739572450155, 00030 0.1208650973866179e-2, -0.5395239384953e-5}; 00031 int j; 00032 double x = xx - 1.0; 00033 double tmp = x + 5.5; 00034 tmp -= (x + 0.5) * std::log(tmp); 00035 double ser = 1.000000000190015; 00036 00037 for ( j = 0; j <= 5; j++ ) { 00038 x += 1.0; 00039 ser += cof[j]/x; 00040 } 00041 return -tmp + std::log(2.5066282746310005*ser); 00042 } 00043 00044 } // namespace CLHEP 00045 00046