GAMMALN
The log-gamma function on the real axis returns the logarithm of the absolute value of the gamma function. It is useful for numerical stability when gamma values are extremely large or small, because logarithms avoid overflow and underflow in many calculations.
The quantity computed is:
\ln\left|\Gamma(x)\right|
This wrapper evaluates the real-valued log-gamma form implemented by SciPy.
Excel Usage
=GAMMALN(x)
x(float, required): Real argument for the log-gamma function.
Returns (float): Natural log of the absolute gamma function at the input.
Example 1: Log-gamma at one
Inputs:
| x |
|---|
| 1 |
Excel formula:
=GAMMALN(1)
Expected output:
0
Example 2: Log-gamma at two
Inputs:
| x |
|---|
| 2 |
Excel formula:
=GAMMALN(2)
Expected output:
0
Example 3: Log-gamma at fractional input
Inputs:
| x |
|---|
| 3.5 |
Excel formula:
=GAMMALN(3.5)
Expected output:
1.20097
Example 4: Log-gamma at large positive input
Inputs:
| x |
|---|
| 25 |
Excel formula:
=GAMMALN(25)
Expected output:
54.7847
Python Code
from scipy.special import gammaln as scipy_gammaln
def gammaln(x):
"""
Compute the natural logarithm of the absolute gamma function.
See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.gammaln.html
This example function is provided as-is without any representation of accuracy.
Args:
x (float): Real argument for the log-gamma function.
Returns:
float: Natural log of the absolute gamma function at the input.
"""
try:
return float(scipy_gammaln(x))
except Exception as e:
return f"Error: {str(e)}"Online Calculator
Real argument for the log-gamma function.