Stan Math Library
5.0.0
Automatic Differentiation
|
double stan::math::opencl_kernels::lgamma_stirling_diff | ( | double | 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 \]
x | value |
Definition at line 45 of file lgamma_stirling_diff.hpp.