Automatic Differentiation
 
Loading...
Searching...
No Matches

◆ lgamma_stirling_diff()

template<typename T >
return_type_t< T > stan::math::lgamma_stirling_diff ( const T  x)

Return the difference between log of the gamma function and its Stirling approximation.

This is useful to stably compute log of ratios of gamma functions with large arguments where the Stirling approximation allows for analytic solution and the (small) differences can be added afterwards. This is for example used in the implementation of lbeta.

The function will return correct value for all arguments, but using it can lead to a loss of precision when x < lgamma_stirling_diff_useful.

\[ \mbox{lgamma_stirling_diff}(x) = \log(\Gamma(x)) - \frac{1}{2} \log(2\pi) + (x-\frac{1}{2})*\log(x) - x \]

Template Parameters
Ttype of value
Parameters
xvalue
Returns
Difference between lgamma(x) and its Stirling approximation.

Definition at line 43 of file lgamma_stirling_diff.hpp.