WPILibC++ 2023.4.3-108-ge5452e3
lgamma.hpp File Reference

Go to the source code of this file.

Namespaces

namespace  internal
 

Functions

constexpr long double internal::lgamma_coef_term (const long double x) noexcept
 
template<typename T >
constexpr T internal::lgamma_term_2 (const T x) noexcept
 
template<typename T >
constexpr T internal::lgamma_term_1 (const T x) noexcept
 
template<typename T >
constexpr T internal::lgamma_begin (const T x) noexcept
 
template<typename T >
constexpr T internal::lgamma_check (const T x) noexcept
 
template<typename T >
constexpr return_t< T > lgamma (const T x) noexcept
 Compile-time log-gamma function. More...
 

Function Documentation

◆ lgamma()

template<typename T >
constexpr return_t< T > lgamma ( const T  x)
constexprnoexcept

Compile-time log-gamma function.

Parameters
xa real-valued input.
Returns
computes the log-gamma function

\[ \ln \Gamma(x) = \ln \int_0^\infty y^{x-1} \exp(-y) dy \]

using a polynomial form:

\[ \Gamma(x+1) \approx (x+g+0.5)^{x+0.5} \exp(-x-g-0.5) \sqrt{2 \pi} \left[ c_0 + \frac{c_1}{x+1} + \frac{c_2}{x+2} + \cdots + \frac{c_n}{x+n} \right] \]

where the value \( g \) and the coefficients \( (c_0, c_1, \ldots, c_n) \) are taken from Paul Godfrey, whose note can be found here: http://my.fit.edu/~gabdo/gamma.txt