Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
gammln.cc
Go to the documentation of this file.
1// $Id:$
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 <cmath>
16
17namespace CLHEP {
18
19double HepStat::gammln(double xx) {
20
21// Returns the value ln(Gamma(xx) for xx > 0. Full accuracy is obtained for
22// xx > 1. For 0 < xx < 1. the reflection formula (6.1.4) can be used first.
23// (Adapted from Numerical Recipes in C. Relative to that routine, this
24// subtracts one from x at the very start, and in exchange does not have to
25// divide ser by x at the end. The results are formally equal, and practically
26// indistinguishable.)
27
28 static double cof[6] = {76.18009172947146,-86.50532032941677,
29 24.01409824083091, -1.231739572450155,
30 0.1208650973866179e-2, -0.5395239384953e-5};
31 int j;
32 double x = xx - 1.0;
33 double tmp = x + 5.5;
34 tmp -= (x + 0.5) * std::log(tmp);
35 double ser = 1.000000000190015;
36
37 for ( j = 0; j <= 5; j++ ) {
38 x += 1.0;
39 ser += cof[j]/x;
40 }
41 return -tmp + std::log(2.5066282746310005*ser);
42}
43
44} // namespace CLHEP
45
46
static double gammln(double x)
Definition: gammln.cc:19
Definition: DoubConv.h:17