4

I am seeking a C or C++ version of gamma and log gamma functions.

Are there any code pieces or libraries recommended?

If possible, I want to know the principle of the implementations.

Thank you!!!

kimi
  • 123
  • 3
  • 6
  • Right the first google hits are http://www.johndcook.com/cpp_gamma.html and http://en.wikipedia.org/wiki/Gamma_function – Olaf Dietsche Mar 18 '13 at 08:59

3 Answers3

11

In c++11, you can use std::lgamma for log gamma, and tgamma for gamma.

BЈовић
  • 62,405
  • 41
  • 173
  • 273
1

You can try to have a look at Numerical Recipes In C, it should contain the functions you need.

Felice Pollano
  • 32,832
  • 9
  • 75
  • 115
1

If you can't use C++11: The GNU GSL has all Gamma function you would ever need: http://www.gnu.org/software/gsl/manual/html_node/Gamma-Functions.html#index-gsl_005fsf_005flngamma-583

Or you can have a look at boost's math special functions: http://www.boost.org/doc/libs/1_53_0/libs/math/doc/sf_and_dist/html/math_toolkit/special/sf_gamma/lgamma.html

us2012
  • 16,083
  • 3
  • 46
  • 62