GAMMALN function
Returns the natural logarithm of the gamma function, a safe way to work with huge factorials without overflow.
Available in All versions of Excel, including Microsoft 365 and Excel for the web
In every Excel versionWorks in Google Sheets
Syntax
GAMMALN(x)| Argument | What it means | |
|---|---|---|
x | Required | A positive number. |
Returns: The value ln(Γ(x)).
How GAMMALN works
Factorials grow explosively: 171! is already too large for Excel, so =FACT(171) returns #NUM!. Taking logarithms tames the numbers. GAMMALN returns ln(Γ(x)), and because Γ(n+1) = n!, GAMMALN(n+1) is the natural log of n factorial. Logs turn products into sums and ratios into differences, so you can combine several giant factorials and convert back with EXP at the end.
This is how statisticians compute binomial and other probabilities with very large counts, and it is how you can check a COMBIN result for large inputs. Unlike GAMMA, GAMMALN only accepts positive inputs. GAMMALN.PRECISE is the newer name for the same calculation; both give identical results in current Excel.
Examples
1Log of 100 factorial
| A | B | |
|---|---|---|
| 1 | n | ln(n!) |
| 2 | 100 | 363.7394 |
Result: 363.7394
100! has 158 digits, but its natural log is just 363.739376 (shown to 4 decimals). =EXP(B2) would turn it back into 9.3326E+157.
2Ratio of two big factorials
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Item | Value | ||
| 2 | n | 100 | 9900 | |
| 3 | k | 98 |
Result: 9900
100!/98! = 100 × 99 = 9,900. Subtracting the logs and applying EXP returns 9900.000000, which Excel displays as 9900 in General format. The same trick works when the factorials themselves would overflow.
Common errors and how to fix them
| Error | Why it happens | Fix |
|---|---|---|
#NUM! | x is 0 or negative. | GAMMALN needs a positive argument; for negative non-integers use =LN(ABS(GAMMA(x))). |
#VALUE! | x is text. | Make sure the cell contains a number. |
Tips
GAMMALN(n+1)=LN(FACT(n))for whole n, but keeps working long after FACT overflows.- Results of EXP(GAMMALN(...)) can carry tiny floating-point noise; wrap them in ROUND when you expect a whole number.
Google Sheets
GAMMALN also exists in Google Sheets and works the same way for everyday use, so the examples above work there too.
GAMMALN in other languages
In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.
| Language | Function name |
|---|---|
| Dutch | GAMMA.LN |
| French | LNGAMMA |
| Italian | LN.GAMMA |
| Polish | ROZKŁAD.LIN.GAMMA |
| Portuguese (Brazil) | LNGAMA |
| Portuguese (Portugal) | LNGAMA |
| Russian | ГАММАНЛОГ |
| Spanish | GAMMA.LN |
| Turkish | GAMALN |