# $$\text{lnGamma}$$¶

You can use the $$\text{lnGamma}$$ function to calculate the natural log of the gamma function directly.

You can use the \lngamma backslash command to insert this function.

The following variants of this function are available:

• $$\text{complex } \text{lnGamma} \left ( \text{<value>} \right )$$

Where $$\text{<value>}$$ represents the value of interest.

Note that run-time type conversion allows the result of this function to be assigned to any basic type provided the returned value is compatible with that type. The compiler will also select appropriate variants of the function if the return type can be determined at compile time based on the supplied parameters.

Aion will detect the construct $$\ln \left ( \Gamma x \right )$$ and will use the $$\text{lnGamma}$$ function rather than calculating the log of the gamma function as two distinct operations.

For cases where $$\text{<value>}$$ is an integer value greater than zero, this function uses the $$\text{lnFactorial}$$ function.

For values where the real portion of $$\text{<value>}$$ is less than $$\frac{1}{2}$$, this function attempts to use the Lanczos approximation with the reflection formula

$\Gamma \left ( x \right ) = \frac{\pi}{ \sin \left ( \pi x \right ) \Gamma \left ( 1 - x \right ) } \;\;\;\;\; x \notin \mathbb{Z}$

falling back to Sterling’s approximation (with the reflection formula) if the Lanczos approximation fails due to the magnitude of the intermediate result.

For small values where the real portion of the parameter is greater than or equal to $$\frac{1}{2}$$, this function simply calculates the gamma function of $$\text{<value>}$$ using Lanczos approximation [4] and then takes the natural logarithm of the result.

For large positive values of the real portion of $$\text{<value>}$$, this function uses Sterling’s approximation of the gamma function which calculates $$\ln \left ( \Gamma x \right )$$ directly noting that only a few terms of Sterling’s approximation are required to reach high accuracy when $$\text{<value>}$$ is sufficiently large.

Note

Aion will detect the construct $$\text{ln} \left ( \Gamma x \right )$$ and will use this function rather than calculate the natural log of the gamma function as two distinct operations.

The example below demonstrates how you can use this function:

$a = \text{lnGamma } 4$
$\text{a = 1.7917594692280549573}$