CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
gammln.cc
Go to the documentation of this file.
1// $Id: gammln.cc,v 1.3 2003/08/13 20:00:12 garren Exp $
2// -*- C++ -*-
3//
4// -----------------------------------------------------------------------
5// HEP Random
6// --- HepStat::gammln ---
7// method implementation file
8// -----------------------------------------------------------------------
9
10// =======================================================================
11// M. Fischler - moved the gammln from RandPoisson to here. 01/26/00
12// =======================================================================
13
14#include "CLHEP/Random/Stat.h"
15#include "CLHEP/Random/defs.h"
16#include <cmath>
17
18namespace CLHEP {
19
20double HepStat::gammln(double xx) {
21
22// Returns the value ln(Gamma(xx) for xx > 0. Full accuracy is obtained for
23// xx > 1. For 0 < xx < 1. the reflection formula (6.1.4) can be used first.
24// (Adapted from Numerical Recipes in C. Relative to that routine, this
25// subtracts one from x at the very start, and in exchange does not have to
26// divide ser by x at the end. The results are formally equal, and practically
27// indistinguishable.)
28
29 static const double cof[6] = {76.18009172947146,-86.50532032941677,
30 24.01409824083091, -1.231739572450155,
31 0.1208650973866179e-2, -0.5395239384953e-5};
32 int j;
33 double x = xx - 1.0;
34 double tmp = x + 5.5;
35 tmp -= (x + 0.5) * std::log(tmp);
36 double ser = 1.000000000190015;
37
38 for ( j = 0; j <= 5; j++ ) {
39 x += 1.0;
40 ser += cof[j]/x;
41 }
42 return -tmp + std::log(2.5066282746310005*ser);
43}
44
45} // namespace CLHEP
46
47
static double gammln(double x)
Definition: gammln.cc:20