1 #ifndef STAN_MATH_PRIM_FUN_LGAMMA_STIRLING_HPP 2 #define STAN_MATH_PRIM_FUN_LGAMMA_STIRLING_HPP 3 4 #include <stan/math/prim/meta.hpp> 5 #include <stan/math/prim/fun/constants.hpp> 6 #include <stan/math/prim/fun/lgamma.hpp> 7 #include <stan/math/prim/fun/log.hpp> 8 #include <cmath> 9 10 namespace stan { 11 namespace math { 12 13 /** 14 * Return the Stirling approximation to the lgamma function. 15 * 16 \f[ 17 \mbox{lgamma_stirling}(x) = 18 \frac{1}{2} \log(2\pi) + (x-\frac{1}{2})*\log(x) - x 19 \f] 20 * 21 * @tparam T type of value 22 * @param x value 23 * @return Stirling's approximation to lgamma(x). 24 */ 25 template <typename T> lgamma_stirling(const T x)26return_type_t<T> lgamma_stirling(const T x) { 27 return HALF_LOG_TWO_PI + (x - 0.5) * log(x) - x; 28 } 29 30 } // namespace math 31 } // namespace stan 32 33 #endif 34