WPILibC++ 2024.3.2
gcem Namespace Reference

Namespaces

namespace  internal
 

Typedefs

using uint_t = unsigned int
 
using ullint_t = unsigned long long int
 
using llint_t = long long int
 
template<class T >
using GCLIM = std::numeric_limits< T >
 
template<typename T >
using return_t = typename std::conditional< std::is_integral< T >::value, double, T >::type
 
template<typename ... T>
using common_t = typename std::common_type< T... >::type
 
template<typename ... T>
using common_return_t = return_t< common_t< T... > >
 

Functions

template<typename T >
constexpr return_t< T > acos (const T x) noexcept
 Compile-time arccosine function. More...
 
template<typename T1 , typename T2 >
constexpr common_t< T1, T2 > binomial_coef (const T1 n, const T2 k) noexcept
 Compile-time binomial coefficient. More...
 
template<typename T1 , typename T2 , typename T3 >
constexpr common_return_t< T1, T2, T3 > incomplete_beta (const T1 a, const T2 b, const T3 z) noexcept
 Compile-time regularized incomplete beta function. More...
 
template<typename T1 , typename T2 >
constexpr common_return_t< T1, T2 > atan2 (const T1 y, const T2 x) noexcept
 Compile-time two-argument arctangent function. More...
 
template<typename T >
constexpr return_t< T > expm1 (const T x) noexcept
 Compile-time exponential-minus-1 function. More...
 
template<typename T1 , typename T2 >
constexpr return_t< T1 > lmgamma (const T1 a, const T2 p) noexcept
 Compile-time log multivariate gamma function. More...
 
template<typename T >
constexpr T abs (const T x) noexcept
 Compile-time absolute value function. More...
 
template<typename T1 , typename T2 >
constexpr common_t< T1, T2 > max (const T1 x, const T2 y) noexcept
 Compile-time pairwise maximum function. More...
 
template<typename T >
constexpr return_t< T > trunc (const T x) noexcept
 Compile-time trunc function. More...
 
template<typename T1 , typename T2 >
constexpr common_t< T1, T2 > lcm (const T1 a, const T2 b) noexcept
 Compile-time least common multiple (LCM) function. More...
 
template<typename T >
constexpr return_t< T > erf (const T x) noexcept
 Compile-time Gaussian error function. More...
 
template<typename T >
constexpr return_t< T > tanh (const T x) noexcept
 Compile-time hyperbolic tangent function. More...
 
template<typename T >
constexpr return_t< T > atanh (const T x) noexcept
 Compile-time inverse hyperbolic tangent function. More...
 
template<typename T >
constexpr return_t< T > inv_sqrt (const T x) noexcept
 Compile-time inverse-square-root function. More...
 
template<typename T >
constexpr return_t< T > log1p (const T x) noexcept
 Compile-time natural-logarithm-plus-1 function. More...
 
template<typename T1 , typename T2 >
constexpr common_return_t< T1, T2 > lbeta (const T1 a, const T2 b) noexcept
 Compile-time log-beta function. More...
 
template<typename T >
constexpr int sgn (const T x) noexcept
 Compile-time sign function. More...
 
template<typename T1 , typename T2 >
constexpr common_return_t< T1, T2 > log_binomial_coef (const T1 n, const T2 k) noexcept
 Compile-time log binomial coefficient. More...
 
template<typename T1 , typename T2 >
constexpr common_return_t< T1, T2 > beta (const T1 a, const T2 b) noexcept
 Compile-time beta function. More...
 
template<typename T >
constexpr return_t< T > round (const T x) noexcept
 Compile-time round function. More...
 
template<typename T >
constexpr return_t< T > lgamma (const T x) noexcept
 Compile-time log-gamma function. More...
 
template<typename T >
constexpr return_t< T > log (const T x) noexcept
 Compile-time natural logarithm function. More...
 
template<typename T1 , typename T2 >
constexpr common_t< T1, T2 > pow (const T1 base, const T2 exp_term) noexcept
 Compile-time power function. More...
 
template<typename T1 , typename T2 >
constexpr common_t< T1, T2 > min (const T1 x, const T2 y) noexcept
 Compile-time pairwise minimum function. More...
 
template<typename T >
constexpr return_t< T > log2 (const T x) noexcept
 Compile-time binary logarithm function. More...
 
template<typename T >
constexpr return_t< T > cos (const T x) noexcept
 Compile-time cosine function. More...
 
template<typename T >
constexpr return_t< T > acosh (const T x) noexcept
 Compile-time inverse hyperbolic cosine function. More...
 
template<typename T >
constexpr bool signbit (const T x) noexcept
 Compile-time sign bit detection function. More...
 
template<typename T >
constexpr return_t< T > sinh (const T x) noexcept
 Compile-time hyperbolic sine function. More...
 
template<typename T >
constexpr return_t< T > asinh (const T x) noexcept
 Compile-time inverse hyperbolic sine function. More...
 
template<typename T1 , typename T2 >
constexpr T1 copysign (const T1 x, const T2 y) noexcept
 Compile-time copy sign function. More...
 
template<typename T >
constexpr return_t< T > sin (const T x) noexcept
 Compile-time sine function. More...
 
template<typename T >
constexpr return_t< T > atan (const T x) noexcept
 Compile-time arctangent function. More...
 
template<typename T >
constexpr return_t< T > log10 (const T x) noexcept
 Compile-time common logarithm function. More...
 
template<typename T >
constexpr return_t< T > tan (const T x) noexcept
 Compile-time tangent function. More...
 
template<typename T >
constexpr return_t< T > exp (const T x) noexcept
 Compile-time exponential function. More...
 
template<typename T >
constexpr T factorial (const T x) noexcept
 Compile-time factorial function. More...
 
template<typename T1 , typename T2 >
constexpr common_return_t< T1, T2 > fmod (const T1 x, const T2 y) noexcept
 Compile-time remainder of division function. More...
 
template<typename T1 , typename T2 , typename T3 >
constexpr common_t< T1, T2, T3 > incomplete_beta_inv (const T1 a, const T2 b, const T3 p) noexcept
 Compile-time inverse incomplete beta function. More...
 
template<typename T1 , typename T2 >
constexpr common_t< T1, T2 > gcd (const T1 a, const T2 b) noexcept
 Compile-time greatest common divisor (GCD) function. More...
 
template<typename T >
constexpr return_t< T > erf_inv (const T p) noexcept
 Compile-time inverse Gaussian error function. More...
 
template<typename T >
constexpr return_t< T > sqrt (const T x) noexcept
 Compile-time square-root function. More...
 
template<typename T >
constexpr return_t< T > cosh (const T x) noexcept
 Compile-time hyperbolic cosine function. More...
 
template<typename T >
constexpr return_t< T > asin (const T x) noexcept
 Compile-time arcsine function. More...
 
template<typename T >
constexpr return_t< T > ceil (const T x) noexcept
 Compile-time ceil function. More...
 
template<typename T1 , typename T2 >
constexpr common_return_t< T1, T2 > incomplete_gamma_inv (const T1 a, const T2 p) noexcept
 Compile-time inverse incomplete gamma function. More...
 
template<typename T >
constexpr return_t< T > tgamma (const T x) noexcept
 Compile-time gamma function. More...
 
template<typename T1 , typename T2 >
constexpr common_return_t< T1, T2 > hypot (const T1 x, const T2 y) noexcept
 Compile-time Pythagorean addition function. More...
 
template<typename T1 , typename T2 , typename T3 >
constexpr common_return_t< T1, T2, T3 > hypot (const T1 x, const T2 y, const T3 z) noexcept
 Compile-time Pythagorean addition function. More...
 
template<typename T >
constexpr return_t< T > floor (const T x) noexcept
 Compile-time floor function. More...
 
template<typename T1 , typename T2 >
constexpr common_return_t< T1, T2 > incomplete_gamma (const T1 a, const T2 x) noexcept
 Compile-time regularized lower incomplete gamma function. More...
 

Variables

static const long double gauss_legendre_30_points [30]
 
static const long double gauss_legendre_30_weights [30]
 
static const long double gauss_legendre_50_points [50]
 
static const long double gauss_legendre_50_weights [50]
 

Typedef Documentation

◆ common_return_t

template<typename ... T>
using gcem::common_return_t = typedef return_t<common_t<T...> >

◆ common_t

template<typename ... T>
using gcem::common_t = typedef typename std::common_type<T...>::type

◆ GCLIM

template<class T >
using gcem::GCLIM = typedef std::numeric_limits<T>

◆ llint_t

using gcem::llint_t = typedef long long int

◆ return_t

template<typename T >
using gcem::return_t = typedef typename std::conditional<std::is_integral<T>::value,double,T>::type

◆ uint_t

using gcem::uint_t = typedef unsigned int

◆ ullint_t

using gcem::ullint_t = typedef unsigned long long int

Function Documentation

◆ abs()

template<typename T >
constexpr T gcem::abs ( const T  x)
constexprnoexcept

Compile-time absolute value function.

Parameters
xa real-valued input.
Returns
the absolute value of x, \( |x| \).

◆ acos()

template<typename T >
constexpr return_t< T > gcem::acos ( const T  x)
constexprnoexcept

Compile-time arccosine function.

Parameters
xa real-valued input, where \( x \in [-1,1] \).
Returns
the inverse cosine function using

\[ \text{acos}(x) = \text{atan} \left( \frac{\sqrt{1-x^2}}{x} \right) \]

◆ acosh()

template<typename T >
constexpr return_t< T > gcem::acosh ( const T  x)
constexprnoexcept

Compile-time inverse hyperbolic cosine function.

Parameters
xa real-valued input.
Returns
the inverse hyperbolic cosine function using

\[ \text{acosh}(x) = \ln \left( x + \sqrt{x^2 - 1} \right) \]

◆ asin()

template<typename T >
constexpr return_t< T > gcem::asin ( const T  x)
constexprnoexcept

Compile-time arcsine function.

Parameters
xa real-valued input, where \( x \in [-1,1] \).
Returns
the inverse sine function using

\[ \text{asin}(x) = \text{atan} \left( \frac{x}{\sqrt{1-x^2}} \right) \]

◆ asinh()

template<typename T >
constexpr return_t< T > gcem::asinh ( const T  x)
constexprnoexcept

Compile-time inverse hyperbolic sine function.

Parameters
xa real-valued input.
Returns
the inverse hyperbolic sine function using

\[ \text{asinh}(x) = \ln \left( x + \sqrt{x^2 + 1} \right) \]

◆ atan()

template<typename T >
constexpr return_t< T > gcem::atan ( const T  x)
constexprnoexcept

Compile-time arctangent function.

Parameters
xa real-valued input.
Returns
the inverse tangent function using

\[ \text{atan}(x) = \dfrac{x}{1 + \dfrac{x^2}{3 + \dfrac{4x^2}{5 + \dfrac{9x^2}{7 + \ddots}}}} \]

◆ atan2()

template<typename T1 , typename T2 >
constexpr common_return_t< T1, T2 > gcem::atan2 ( const T1  y,
const T2  x 
)
constexprnoexcept

Compile-time two-argument arctangent function.

Parameters
ya real-valued input.
xa real-valued input.
Returns

\[ \text{atan2}(y,x) = \begin{cases} \text{atan}(y/x) & \text{ if } x > 0 \\ \text{atan}(y/x) + \pi & \text{ if } x < 0 \text{ and } y \geq 0 \\ \text{atan}(y/x) - \pi & \text{ if } x < 0 \text{ and } y < 0 \\ + \pi/2 & \text{ if } x = 0 \text{ and } y > 0 \\ - \pi/2 & \text{ if } x = 0 \text{ and } y < 0 \end{cases} \]

The function is undefined at the origin, however the following conventions are used.

\[ \text{atan2}(y,x) = \begin{cases} +0 & \text{ if } x = +0 \text{ and } y = +0 \\ -0 & \text{ if } x = +0 \text{ and } y = -0 \\ +\pi & \text{ if } x = -0 \text{ and } y = +0 \\ - \pi & \text{ if } x = -0 \text{ and } y = -0 \end{cases} \]

◆ atanh()

template<typename T >
constexpr return_t< T > gcem::atanh ( const T  x)
constexprnoexcept

Compile-time inverse hyperbolic tangent function.

Parameters
xa real-valued input.
Returns
the inverse hyperbolic tangent function using

\[ \text{atanh}(x) = \frac{1}{2} \ln \left( \frac{1+x}{1-x} \right) \]

◆ beta()

template<typename T1 , typename T2 >
constexpr common_return_t< T1, T2 > gcem::beta ( const T1  a,
const T2  b 
)
constexprnoexcept

Compile-time beta function.

Parameters
aa real-valued input.
ba real-valued input.
Returns
the beta function using

\[ \text{B}(\alpha,\beta) := \int_0^1 t^{\alpha - 1} (1-t)^{\beta - 1} dt = \frac{\Gamma(\alpha)\Gamma(\beta)}{\Gamma(\alpha + \beta)} \]

where \( \Gamma \) denotes the gamma function.

◆ binomial_coef()

template<typename T1 , typename T2 >
constexpr common_t< T1, T2 > gcem::binomial_coef ( const T1  n,
const T2  k 
)
constexprnoexcept

Compile-time binomial coefficient.

Parameters
nintegral-valued input.
kintegral-valued input.
Returns
computes the Binomial coefficient

\[ \binom{n}{k} = \frac{n!}{k!(n-k)!} \]

also known as 'n choose k '.

◆ ceil()

template<typename T >
constexpr return_t< T > gcem::ceil ( const T  x)
constexprnoexcept

Compile-time ceil function.

Parameters
xa real-valued input.
Returns
computes the ceiling-value of the input.

◆ copysign()

template<typename T1 , typename T2 >
constexpr T1 gcem::copysign ( const T1  x,
const T2  y 
)
constexprnoexcept

Compile-time copy sign function.

Parameters
xa real-valued input
ya real-valued input
Returns
replace the signbit of x with the signbit of y.

◆ cos()

template<typename T >
constexpr return_t< T > gcem::cos ( const T  x)
constexprnoexcept

Compile-time cosine function.

Parameters
xa real-valued input.
Returns
the cosine function using

\[ \cos(x) = \frac{1-\tan^2(x/2)}{1+\tan^2(x/2)} \]

◆ cosh()

template<typename T >
constexpr return_t< T > gcem::cosh ( const T  x)
constexprnoexcept

Compile-time hyperbolic cosine function.

Parameters
xa real-valued input.
Returns
the hyperbolic cosine function using

\[ \cosh(x) = \frac{\exp(x) + \exp(-x)}{2} \]

◆ erf()

template<typename T >
constexpr return_t< T > gcem::erf ( const T  x)
constexprnoexcept

Compile-time Gaussian error function.

Parameters
xa real-valued input.
Returns
computes the Gaussian error function

\[ \text{erf}(x) = \frac{2}{\sqrt{\pi}} \int_0^x \exp( - t^2) dt \]

using a continued fraction representation:

\[ \text{erf}(x) = \frac{2x}{\sqrt{\pi}} \exp(-x^2) \dfrac{1}{1 - 2x^2 + \dfrac{4x^2}{3 - 2x^2 + \dfrac{8x^2}{5 - 2x^2 + \dfrac{12x^2}{7 - 2x^2 + \ddots}}}} \]

◆ erf_inv()

template<typename T >
constexpr return_t< T > gcem::erf_inv ( const T  p)
constexprnoexcept

Compile-time inverse Gaussian error function.

Parameters
pa real-valued input with values in the unit-interval.
Returns
Computes the inverse Gaussian error function, a value \( x \) such that

\[ f(x) := \text{erf}(x) - p \]

is equal to zero, for a given p. GCE-Math finds this root using Halley's method:

\[ x_{n+1} = x_n - \frac{f(x_n)/f'(x_n)}{1 - 0.5 \frac{f(x_n)}{f'(x_n)} \frac{f''(x_n)}{f'(x_n)} } \]

where

\[ \frac{\partial}{\partial x} \text{erf}(x) = \exp(-x^2), \ \ \frac{\partial^2}{\partial x^2} \text{erf}(x) = -2x\exp(-x^2) \]

◆ exp()

template<typename T >
constexpr return_t< T > gcem::exp ( const T  x)
constexprnoexcept

Compile-time exponential function.

Parameters
xa real-valued input.
Returns
\( \exp(x) \) using

\[ \exp(x) = \dfrac{1}{1-\dfrac{x}{1+x-\dfrac{\frac{1}{2}x}{1 + \frac{1}{2}x - \dfrac{\frac{1}{3}x}{1 + \frac{1}{3}x - \ddots}}}} \]

The continued fraction argument is split into two parts: \( x = n + r \), where \( n \) is an integer and \( r \in [-0.5,0.5] \).

◆ expm1()

template<typename T >
constexpr return_t< T > gcem::expm1 ( const T  x)
constexprnoexcept

Compile-time exponential-minus-1 function.

Parameters
xa real-valued input.
Returns
\( \exp(x) - 1 \) using

\[ \exp(x) = \sum_{k=0}^\infty \dfrac{x^k}{k!} \]

◆ factorial()

template<typename T >
constexpr T gcem::factorial ( const T  x)
constexprnoexcept

Compile-time factorial function.

Parameters
xa real-valued input.
Returns
Computes the factorial value \( x! \). When x is an integral type (int, long int, etc.), a simple recursion method is used, along with table values. When x is real-valued, factorial(x) = tgamma(x+1).

◆ floor()

template<typename T >
constexpr return_t< T > gcem::floor ( const T  x)
constexprnoexcept

Compile-time floor function.

Parameters
xa real-valued input.
Returns
computes the floor-value of the input.

◆ fmod()

template<typename T1 , typename T2 >
constexpr common_return_t< T1, T2 > gcem::fmod ( const T1  x,
const T2  y 
)
constexprnoexcept

Compile-time remainder of division function.

Parameters
xa real-valued input.
ya real-valued input.
Returns
computes the floating-point remainder of \( x / y \) (rounded towards zero) using

\[ \text{fmod}(x,y) = x - \text{trunc}(x/y) \times y \]

◆ gcd()

template<typename T1 , typename T2 >
constexpr common_t< T1, T2 > gcem::gcd ( const T1  a,
const T2  b 
)
constexprnoexcept

Compile-time greatest common divisor (GCD) function.

Parameters
aintegral-valued input.
bintegral-valued input.
Returns
the greatest common divisor between integers a and b using a Euclidean algorithm.

◆ hypot() [1/2]

template<typename T1 , typename T2 >
constexpr common_return_t< T1, T2 > gcem::hypot ( const T1  x,
const T2  y 
)
constexprnoexcept

Compile-time Pythagorean addition function.

Parameters
xa real-valued input.
ya real-valued input.
Returns
Computes \( x \oplus y = \sqrt{x^2 + y^2} \).

◆ hypot() [2/2]

template<typename T1 , typename T2 , typename T3 >
constexpr common_return_t< T1, T2, T3 > gcem::hypot ( const T1  x,
const T2  y,
const T3  z 
)
constexprnoexcept

Compile-time Pythagorean addition function.

Parameters
xa real-valued input.
ya real-valued input.
za real-valued input.
Returns
Computes \( x \oplus y \oplus z = \sqrt{x^2 + y^2 + z^2} \).

◆ incomplete_beta()

template<typename T1 , typename T2 , typename T3 >
constexpr common_return_t< T1, T2, T3 > gcem::incomplete_beta ( const T1  a,
const T2  b,
const T3  z 
)
constexprnoexcept

Compile-time regularized incomplete beta function.

Parameters
aa real-valued, non-negative input.
ba real-valued, non-negative input.
za real-valued, non-negative input.
Returns
computes the regularized incomplete beta function,

\[ \frac{\text{B}(z;\alpha,\beta)}{\text{B}(\alpha,\beta)} = \frac{1}{\text{B}(\alpha,\beta)}\int_0^z t^{a-1} (1-t)^{\beta-1} dt \]

using a continued fraction representation, found in the Handbook of Continued Fractions for Special Functions, and a modified Lentz method.

\[ \frac{\text{B}(z;\alpha,\beta)}{\text{B}(\alpha,\beta)} = \frac{z^{\alpha} (1-t)^{\beta}}{\alpha \text{B}(\alpha,\beta)} \dfrac{a_1}{1 + \dfrac{a_2}{1 + \dfrac{a_3}{1 + \dfrac{a_4}{1 + \ddots}}}} \]

where \( a_1 = 1 \) and

\[ a_{2m+2} = - \frac{(\alpha + m)(\alpha + \beta + m)}{(\alpha + 2m)(\alpha + 2m + 1)}, \ m \geq 0 \]

\[ a_{2m+1} = \frac{m(\beta - m)}{(\alpha + 2m - 1)(\alpha + 2m)}, \ m \geq 1 \]

The Lentz method works as follows: let \( f_j \) denote the value of the continued fraction up to the first \( j \) terms; \( f_j \) is updated as follows:

\[ c_j = 1 + a_j / c_{j-1}, \ \ d_j = 1 / (1 + a_j d_{j-1}) \]

\[ f_j = c_j d_j f_{j-1} \]

◆ incomplete_beta_inv()

template<typename T1 , typename T2 , typename T3 >
constexpr common_t< T1, T2, T3 > gcem::incomplete_beta_inv ( const T1  a,
const T2  b,
const T3  p 
)
constexprnoexcept

Compile-time inverse incomplete beta function.

Parameters
aa real-valued, non-negative input.
ba real-valued, non-negative input.
pa real-valued input with values in the unit-interval.
Returns
Computes the inverse incomplete beta function, a value \( x \) such that

\[ f(x) := \frac{\text{B}(x;\alpha,\beta)}{\text{B}(\alpha,\beta)} - p \]

equal to zero, for a given p. GCE-Math finds this root using Halley's method:

\[ x_{n+1} = x_n - \frac{f(x_n)/f'(x_n)}{1 - 0.5 \frac{f(x_n)}{f'(x_n)} \frac{f''(x_n)}{f'(x_n)} } \]

where

\[ \frac{\partial}{\partial x} \left(\frac{\text{B}(x;\alpha,\beta)}{\text{B}(\alpha,\beta)}\right) = \frac{1}{\text{B}(\alpha,\beta)} x^{\alpha-1} (1-x)^{\beta-1} \]

\[ \frac{\partial^2}{\partial x^2} \left(\frac{\text{B}(x;\alpha,\beta)}{\text{B}(\alpha,\beta)}\right) = \frac{1}{\text{B}(\alpha,\beta)} x^{\alpha-1} (1-x)^{\beta-1} \left( \frac{\alpha-1}{x} - \frac{\beta-1}{1 - x} \right) \]

◆ incomplete_gamma()

template<typename T1 , typename T2 >
constexpr common_return_t< T1, T2 > gcem::incomplete_gamma ( const T1  a,
const T2  x 
)
constexprnoexcept

Compile-time regularized lower incomplete gamma function.

Parameters
aa real-valued, non-negative input.
xa real-valued, non-negative input.
Returns
the regularized lower incomplete gamma function evaluated at (a, x),

\[ \frac{\gamma(a,x)}{\Gamma(a)} = \frac{1}{\Gamma(a)} \int_0^x t^{a-1} \exp(-t) dt \]

When a is not too large, the value is computed using the continued fraction representation of the upper incomplete gamma function, \( \Gamma(a,x) \), using

\[ \Gamma(a,x) = \Gamma(a) - \dfrac{x^a\exp(-x)}{a - \dfrac{ax}{a + 1 + \dfrac{x}{a + 2 - \dfrac{(a+1)x}{a + 3 + \dfrac{2x}{a + 4 - \ddots}}}}} \]

where \( \gamma(a,x) \) and \( \Gamma(a,x) \) are connected via

\[ \frac{\gamma(a,x)}{\Gamma(a)} + \frac{\Gamma(a,x)}{\Gamma(a)} = 1 \]

When \( a > 10 \), a 50-point Gauss-Legendre quadrature scheme is employed.

◆ incomplete_gamma_inv()

template<typename T1 , typename T2 >
constexpr common_return_t< T1, T2 > gcem::incomplete_gamma_inv ( const T1  a,
const T2  p 
)
constexprnoexcept

Compile-time inverse incomplete gamma function.

Parameters
aa real-valued, non-negative input.
pa real-valued input with values in the unit-interval.
Returns
Computes the inverse incomplete gamma function, a value \( x \) such that

\[ f(x) := \frac{\gamma(a,x)}{\Gamma(a)} - p \]

equal to zero, for a given p. GCE-Math finds this root using Halley's method:

\[ x_{n+1} = x_n - \frac{f(x_n)/f'(x_n)}{1 - 0.5 \frac{f(x_n)}{f'(x_n)} \frac{f''(x_n)}{f'(x_n)} } \]

where

\[ \frac{\partial}{\partial x} \left(\frac{\gamma(a,x)}{\Gamma(a)}\right) = \frac{1}{\Gamma(a)} x^{a-1} \exp(-x) \]

\[ \frac{\partial^2}{\partial x^2} \left(\frac{\gamma(a,x)}{\Gamma(a)}\right) = \frac{1}{\Gamma(a)} x^{a-1} \exp(-x) \left( \frac{a-1}{x} - 1 \right) \]

◆ inv_sqrt()

template<typename T >
constexpr return_t< T > gcem::inv_sqrt ( const T  x)
constexprnoexcept

Compile-time inverse-square-root function.

Parameters
xa real-valued input.
Returns
Computes \( 1 / \sqrt{x} \) using a Newton-Raphson approach.

◆ lbeta()

template<typename T1 , typename T2 >
constexpr common_return_t< T1, T2 > gcem::lbeta ( const T1  a,
const T2  b 
)
constexprnoexcept

Compile-time log-beta function.

Parameters
aa real-valued input.
ba real-valued input.
Returns
the log-beta function using

\[ \ln \text{B}(\alpha,\beta) := \ln \int_0^1 t^{\alpha - 1} (1-t)^{\beta - 1} dt = \ln \Gamma(\alpha) + \ln \Gamma(\beta) - \ln \Gamma(\alpha + \beta) \]

where \( \Gamma \) denotes the gamma function.

◆ lcm()

template<typename T1 , typename T2 >
constexpr common_t< T1, T2 > gcem::lcm ( const T1  a,
const T2  b 
)
constexprnoexcept

Compile-time least common multiple (LCM) function.

Parameters
aintegral-valued input.
bintegral-valued input.
Returns
the least common multiple between integers a and b using the representation

\[ \text{lcm}(a,b) = \dfrac{| a b |}{\text{gcd}(a,b)} \]

where \( \text{gcd}(a,b) \) denotes the greatest common divisor between \( a \) and \( b \).

◆ lgamma()

template<typename T >
constexpr return_t< T > gcem::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

◆ lmgamma()

template<typename T1 , typename T2 >
constexpr return_t< T1 > gcem::lmgamma ( const T1  a,
const T2  p 
)
constexprnoexcept

Compile-time log multivariate gamma function.

Parameters
aa real-valued input.
pintegral-valued input.
Returns
computes log-multivariate gamma function via recursion

\[ \Gamma_p(a) = \pi^{(p-1)/2} \Gamma(a) \Gamma_{p-1}(a-0.5) \]

where \( \Gamma_1(a) = \Gamma(a) \).

◆ log()

template<typename T >
constexpr return_t< T > gcem::log ( const T  x)
constexprnoexcept

Compile-time natural logarithm function.

Parameters
xa real-valued input.
Returns
\( \log_e(x) \) using

\[ \log\left(\frac{1+x}{1-x}\right) = \dfrac{2x}{1-\dfrac{x^2}{3-\dfrac{4x^2}{5 - \dfrac{9x^3}{7 - \ddots}}}}, \ \ x \in [-1,1] \]

The continued fraction argument is split into two parts: \( x = a \times 10^c \), where \( c \) is an integer.

◆ log10()

template<typename T >
constexpr return_t< T > gcem::log10 ( const T  x)
constexprnoexcept

Compile-time common logarithm function.

Parameters
xa real-valued input.
Returns
\( \log_{10}(x) \) using

\[ \log_{10}(x) = \frac{\log_e(x)}{\log_e(10)} \]

◆ log1p()

template<typename T >
constexpr return_t< T > gcem::log1p ( const T  x)
constexprnoexcept

Compile-time natural-logarithm-plus-1 function.

Parameters
xa real-valued input.
Returns
\( \log_e(x+1) \) using

\[ \log(x+1) = \sum_{k=1}^\infty \dfrac{(-1)^{k-1}x^k}{k}, \ \ |x| < 1 \]

◆ log2()

template<typename T >
constexpr return_t< T > gcem::log2 ( const T  x)
constexprnoexcept

Compile-time binary logarithm function.

Parameters
xa real-valued input.
Returns
\( \log_2(x) \) using

\[ \log_{2}(x) = \frac{\log_e(x)}{\log_e(2)} \]

◆ log_binomial_coef()

template<typename T1 , typename T2 >
constexpr common_return_t< T1, T2 > gcem::log_binomial_coef ( const T1  n,
const T2  k 
)
constexprnoexcept

Compile-time log binomial coefficient.

Parameters
nintegral-valued input.
kintegral-valued input.
Returns
computes the log Binomial coefficient

\[ \ln \frac{n!}{k!(n-k)!} = \ln \Gamma(n+1) - [ \ln \Gamma(k+1) + \ln \Gamma(n-k+1) ] \]

◆ max()

template<typename T1 , typename T2 >
constexpr common_t< T1, T2 > gcem::max ( const T1  x,
const T2  y 
)
constexprnoexcept

Compile-time pairwise maximum function.

Parameters
xa real-valued input.
ya real-valued input.
Returns
Computes the maximum between x and y, where x and y have the same type (e.g., int, double, etc.)

◆ min()

template<typename T1 , typename T2 >
constexpr common_t< T1, T2 > gcem::min ( const T1  x,
const T2  y 
)
constexprnoexcept

Compile-time pairwise minimum function.

Parameters
xa real-valued input.
ya real-valued input.
Returns
Computes the minimum between x and y, where x and y have the same type (e.g., int, double, etc.)

◆ pow()

template<typename T1 , typename T2 >
constexpr common_t< T1, T2 > gcem::pow ( const T1  base,
const T2  exp_term 
)
constexprnoexcept

Compile-time power function.

Parameters
basea real-valued input.
exp_terma real-valued input.
Returns
Computes base raised to the power exp_term. In the case where exp_term is integral-valued, recursion by squaring is used, otherwise \( \text{base}^{\text{exp\_term}} = e^{\text{exp\_term} \log(\text{base})} \)

◆ round()

template<typename T >
constexpr return_t< T > gcem::round ( const T  x)
constexprnoexcept

Compile-time round function.

Parameters
xa real-valued input.
Returns
computes the rounding value of the input.

◆ sgn()

template<typename T >
constexpr int gcem::sgn ( const T  x)
constexprnoexcept

Compile-time sign function.

Parameters
xa real-valued input
Returns
a value \( y \) such that

\[ y = \begin{cases} 1 \ &\text{ if } x > 0 \\ 0 \ &\text{ if } x = 0 \\ -1 \ &\text{ if } x < 0 \end{cases} \]

◆ signbit()

template<typename T >
constexpr bool gcem::signbit ( const T  x)
constexprnoexcept

Compile-time sign bit detection function.

Parameters
xa real-valued input
Returns
return true if x is negative, otherwise return false.

◆ sin()

template<typename T >
constexpr return_t< T > gcem::sin ( const T  x)
constexprnoexcept

Compile-time sine function.

Parameters
xa real-valued input.
Returns
the sine function using

\[ \sin(x) = \frac{2\tan(x/2)}{1+\tan^2(x/2)} \]

◆ sinh()

template<typename T >
constexpr return_t< T > gcem::sinh ( const T  x)
constexprnoexcept

Compile-time hyperbolic sine function.

Parameters
xa real-valued input.
Returns
the hyperbolic sine function using

\[ \sinh(x) = \frac{\exp(x) - \exp(-x)}{2} \]

◆ sqrt()

template<typename T >
constexpr return_t< T > gcem::sqrt ( const T  x)
constexprnoexcept

Compile-time square-root function.

Parameters
xa real-valued input.
Returns
Computes \( \sqrt{x} \) using a Newton-Raphson approach.

◆ tan()

template<typename T >
constexpr return_t< T > gcem::tan ( const T  x)
constexprnoexcept

Compile-time tangent function.

Parameters
xa real-valued input.
Returns
the tangent function using

\[ \tan(x) = \dfrac{x}{1 - \dfrac{x^2}{3 - \dfrac{x^2}{5 - \ddots}}} \]

To deal with a singularity at \( \pi / 2 \), the following expansion is employed:

\[ \tan(x) = - \frac{1}{x-\pi/2} - \sum_{k=1}^\infty \frac{(-1)^k 2^{2k} B_{2k}}{(2k)!} (x - \pi/2)^{2k - 1} \]

where \( B_n \) is the n-th Bernoulli number.

◆ tanh()

template<typename T >
constexpr return_t< T > gcem::tanh ( const T  x)
constexprnoexcept

Compile-time hyperbolic tangent function.

Parameters
xa real-valued input.
Returns
the hyperbolic tangent function using

\[ \tanh(x) = \dfrac{x}{1 + \dfrac{x^2}{3 + \dfrac{x^2}{5 + \dfrac{x^2}{7 + \ddots}}}} \]

◆ tgamma()

template<typename T >
constexpr return_t< T > gcem::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

◆ trunc()

template<typename T >
constexpr return_t< T > gcem::trunc ( const T  x)
constexprnoexcept

Compile-time trunc function.

Parameters
xa real-valued input.
Returns
computes the trunc-value of the input, essentially returning the integer part of the input.

Variable Documentation

◆ gauss_legendre_30_points

const long double gcem::gauss_legendre_30_points[30]
static

◆ gauss_legendre_30_weights

const long double gcem::gauss_legendre_30_weights[30]
static

◆ gauss_legendre_50_points

const long double gcem::gauss_legendre_50_points[50]
static

◆ gauss_legendre_50_weights

const long double gcem::gauss_legendre_50_weights[50]
static