Revision 601 trunk/src/linad99/combc.cpp

combc.cpp (revision 601)
1
/*
1
/**
2 2
 * $Id$
3 3
 *
4 4
 * Author: David Fournier
......
14 14

  
15 15
double factln(double n);
16 16
double gammln(double xx);
17
double lgam(double xx);
18 17

  
19 18
/**
20 19
 * Log of the binomial coefficent
......
38 37
  return gammln(n+1.0);
39 38
}
40 39

  
41
/**
42
 * A wrapper for igam
43
 */
40
/** Log gamma function.
41
    \param xx \f$x\f$
42
    \return \f$\ln\bigr(\Gamma(x)\bigl)\f$
43

  
44
    \n\n The implementation of this algorithm was inspired by
45
    "Numerical Recipes in C", 2nd edition,
46
    Press, Teukolsky, Vetterling, Flannery, chapter 6
47
*/
44 48
double gammln(double xx)
45 49
{
46
  return lgam(xx);
50
  double x,tmp,ser;
51
  static double cof[6]={76.18009173,-86.50532033,24.01409822,
52
    -1.231739516,0.120858003e-2,-0.536382e-5};
53
  int j;
54
  x=xx-1.0;
55
  tmp=x+5.5;
56
  tmp -= (x+0.5)*log(tmp);
57
  ser=1.0;
58
  for (j=0;j<=5;j++) 
59
  {
60
    x += 1.0;
61
    ser += cof[j]/x;
62
  }
63
  return -tmp+log(2.50662827465*ser);
47 64
}
48 65

  
49 66
/**

Also available in: Unified diff