WPILibC++ 2023.4.3
tgamma.hpp File Reference

Go to the source code of this file.

Namespaces

namespace  internal
 

Functions

template<typename T >
constexpr T internal::tgamma_check (const T x) noexcept
 
template<typename T >
constexpr return_t< T > tgamma (const T x) noexcept
 Compile-time gamma function. More...
 

Function Documentation

◆ tgamma()

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

Compile-time gamma function.

Parameters
xa real-valued input.
Returns
computes the ‘true’ gamma function

\[ \Gamma(x) = \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