GAMMALN in Excel: Log-Factorials and Stable Ratios
Calculate natural logarithms of gamma values in Excel, work with factorial ratios in log space, and keep the required positive input domain explicit.
Verification status: See the evidence and test scope described in this guide. How formula examples are checked
Quick answer: GAMMALN(x) returns the natural logarithm of gamma(x), with x>0. For a positive integer n, it equals LN((n−1)!). It is useful when the logarithm or a ratio matters more than the potentially large gamma value itself.
Syntax and input meaning
=GAMMALN(x)
The argument is required. This is a natural logarithm, base e; it is not a base-10 logarithm. Microsoft documents #NUM! for x≤0 and #VALUE! for a nonnumeric argument. Although GAMMA itself has real values at some negative inputs, GAMMALN’s documented positive-input restriction remains in force.
The output may be zero or negative even though x must be positive. Input-domain restrictions do not impose the same restriction on the result.
Example 1: familiar factorial anchors
=GAMMALN(1)
=GAMMALN(2)
=GAMMALN(4)
=GAMMALN(6)
Expected results are 0, 0, 1.791759469 and 4.787491743. The last two are LN(6) and LN(120), because gamma(4)=3! and gamma(6)=5!.
For integer n in A2, the log of n! therefore uses:
=GAMMALN(A2+1)
At n=5 the answer is approximately 4.787491743. Omitting the +1 calculates the log of 4!, a different quantity.
Example 2: a negative logarithm is valid
=GAMMALN(1.5)
=EXP(GAMMALN(1.5))
Expected results are approximately -0.120782238 and 0.886226925. The gamma value lies between zero and one, so its natural logarithm is negative. There is no need to take an absolute value or replace that logarithm with zero.
The exponential reverses the logarithm in this moderate example. It should not be used reflexively if the next analysis can stay in log space.
Advanced application: a log binomial coefficient
For nonnegative integer n and integer k with 0≤k≤n, a combinatorial coefficient can be expressed as a difference of log-factorials. Put n=10 in A2 and k=3 in B2:
=GAMMALN(A2+1)-GAMMALN(B2+1)-GAMMALN(A2-B2+1)
Expected log coefficient: 4.787491743. Exponentiating that cell gives approximately 120, the number of ways to choose 3 positions from 10.
Validate the integer constraints separately. GAMMALN will accept many fractional inputs that have mathematical values, but those inputs do not automatically describe the ordinary count of combinations. For a small exact count, COMBIN is usually clearer; the log expression is helpful in larger likelihood calculations.
Advanced application: combine multiplication and division as sums
Suppose a model requires gamma(9)/[gamma(4)×gamma(6)]. Compute:
=GAMMALN(9)-GAMMALN(4)-GAMMALN(6)
=EXP(GAMMALN(9)-GAMMALN(4)-GAMMALN(6))
Expected values are approximately 4.025351691 and 56. The first formula keeps the entire expression in log space. The second returns the ordinary scale only at the end.
This strategy reduces dependence on large intermediate products. It does not guarantee exact subtraction of nearly equal log values, and EXP can still overflow if the final result is too large. Keep a log result when that is what the downstream calculation actually needs.
Recurrence and a reproducible column control
Enter 1, 2, 3, 4 and 5 in A2:A6. Compare GAMMALN(A2+1)-GAMMALN(A2) with LN(A2). The expected differences are 0, 0.693147181, 1.098612289, 1.386294361 and 1.609437912.
This follows from gamma(x+1)=x×gamma(x) for positive x. Allow a suitable numerical tolerance rather than asserting exact equality for every floating-point evaluation.
Troubleshooting
If an answer differs from a desired factorial log, first check the +1 offset. If it differs from a base-10 expectation, remember that the conversion is GAMMALN(x)/LN(10). If #NUM! appears, inspect the actual x value before hiding the error; zero cannot be used as a placeholder for an unknown positive parameter.
Text coercion, blank-cell behavior, extreme inputs and Excel’s platform-specific rounding have not been executed here. GAMMALN.PRECISE is a separately named function; the examples do not establish an accuracy ranking between implementations.
Availability and version history
- Current documentation: the dedicated Microsoft reference lists Excel for Microsoft 365, Excel for Microsoft 365 for Mac, Excel 2024, Excel 2024 for Mac, Excel 2021, Excel 2021 for Mac, Excel 2019, Excel 2016.
- Introduced: the first introduction version/build is not established by the dedicated reference used here.
- Last functioning version: unknown; a current help listing is not a last-working-build test.
- Evidence checked: October 15, 2026. Official documentation was freshly retrieved; examples below were independently calculated. No native Excel, Mac or web-client execution was performed.
References and verification
Examples use English function names and comma separators. Expected numbers are rounded independent mathematical calculations; documented error expectations are labeled as such. They are not captured Excel output. All illustrative data and policies are fictional.