Stan Math Library
5.0.0
Automatic Differentiation
|
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 \]
T | type of value |
x | value |
Definition at line 43 of file lgamma_stirling_diff.hpp.