GAMMALN.PRECISE returns the natural logarithm of the gamma function for a given positive number. It is useful when gamma values become too large to store directly, because the log keeps the numbers manageable.
=GAMMALN.PRECISE(x)What does GAMMALN.PRECISE do?
GAMMALN.PRECISE calculates the natural logarithm of the gamma function, written as ln(Γ(x)). The gamma function extends the idea of a factorial to non-integer numbers, so Γ(5) equals 24, just like 4!. Because gamma values grow extremely quickly, Excel also offers the log version, which stays within normal numeric limits for much larger inputs.
You will meet this function in statistics and probability work. The gamma function appears in the gamma distribution, the chi-square distribution and the beta distribution, and log-gamma values are used in likelihood calculations and in combinatorics. If you tried to compute a factorial or gamma value directly for a large number, Excel would return an error; GAMMALN.PRECISE avoids that by working on the log scale.
A practical situation: an analyst is fitting a gamma distribution to call-centre waiting times and needs log-likelihood values. The gamma term in the likelihood is a log-gamma value, so a column of GAMMALN.PRECISE results feeds straight into the model. The function is built into Excel and needs no add-in.
When to use GAMMALN.PRECISE
- Calculating log-likelihoods for gamma, chi-square or beta distributions.
- Working with factorials or gamma values too large for direct calculation.
- Converting products of gamma terms into sums of logs in statistical models.
- Checking gamma-function identities in coursework or research.
- Computing combinatorial quantities on the log scale to avoid overflow.
GAMMALN.PRECISE syntax
=GAMMALN.PRECISE(x)| Argument | Required? | What to enter |
|---|---|---|
x | Required | The positive number whose gamma function you want the natural log of. It must be greater than zero; for example, =GAMMALN.PRECISE(5) returns about 3.178. |
What it returns: A single number: the natural logarithm of the gamma function evaluated at x. For positive integers n, the result equals LN(FACT(n-1)).
GAMMALN.PRECISE examples
1 Example 1: Log gamma of a single number
The goal is to see what GAMMALN.PRECISE returns for a small integer. The formula =GAMMALN.PRECISE(B2) reads the value 5 in cell B2. Because Γ(5) = 4! = 24, the function returns LN(24), which is approximately 3.178. This confirms the link between the gamma function and factorials.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Input | Value | |||
| 2 | x | 5 | 3.17805383 | ||
| 3 | Factorial check | 24 | |||
| 4 | LN of check | 3.17805383 | |||
| 5 | Note | Gamma(5) = 4! | |||
| 6 |
2 Example 2: Log gamma for non-integer values
The goal is to show that GAMMALN.PRECISE accepts decimals, not just whole numbers. The formula =GAMMALN.PRECISE(B2) uses the value 2.5 from B2. The gamma function at 2.5 is about 1.32934, so its natural log is about 0.28468. This is where the function goes beyond ordinary factorials.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Input | Value | |||
| 2 | x | 2.5 | 0.2846828705 | ||
| 3 | Gamma(2.5) | 1.329340388 | |||
| 4 | LN of Gamma | 0.2846828705 | |||
| 5 | Note | Non-integer input | |||
| 6 |
3 Example 3: Avoiding overflow with large numbers
The goal is to handle a large input that would break a direct factorial calculation. The formula =GAMMALN.PRECISE(B2) uses 100 from B2. FACT(99) is far too large for Excel, but the log-gamma value is a manageable number, about 359.134. The result lets you keep working on the log scale without an overflow error.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Input | Value | |||
| 2 | x | 100 | 359.1342054 | ||
| 3 | Factorial equivalent | FACT(99) | |||
| 4 | Log-gamma result | 359.1342054 | |||
| 5 | Note | Direct factorial overflows | |||
| 6 |
4 Example 4: Log-likelihood term for a gamma distribution
The goal is to compute the log-gamma term used in a gamma-distribution log-likelihood. The formula =GAMMALN.PRECISE(B2) reads the shape parameter 3 from B2. The result, about 0.693147, is LN(2), because Γ(3) = 2! = 2. In a real model this term would be subtracted from other log terms to build the full likelihood.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Parameter | Value | |||
| 2 | Shape (k) | 3 | 0.6931471806 | ||
| 3 | Scale (theta) | 2 | |||
| 4 | Gamma(k) | 2 | |||
| 5 | Log-gamma term | 0.6931471806 | |||
| 6 |
5 Example 5: Combining log-gamma with other log terms
The goal is to show GAMMALN.PRECISE inside a larger statistical expression. The formula =GAMMALN.PRECISE(B2)-B3*LN(B4) uses the shape parameter 4 from B2, the count 2 from B3 and the rate 1.5 from B4. GAMMALN.PRECISE(4) is LN(6), about 1.79176, and the second term is about 0.81093, so the result is about 0.98083. This mirrors how log-gamma terms are combined with other logs in likelihood work.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Item | Value | |||
| 2 | Shape (k) | 4 | 0.980829253 | ||
| 3 | Count (n) | 2 | |||
| 4 | Rate | 1.5 | |||
| 5 | Log-gamma(k) | 1.791759469 | |||
| 6 | n*LN(rate) | 0.8109302162 | |||
| 7 |
Common GAMMALN.PRECISE errors and how to fix them
| Error | Why it happens | How to fix it |
|---|---|---|
| #NUM! | The argument is zero or negative, which is outside the domain of the gamma function. | Use a positive number. Check the source cell and correct or filter out non-positive values before calling the function. |
| #VALUE! | The argument is text that cannot be interpreted as a number, such as an empty text string or a word. | Point the formula at a numeric cell, or convert the text to a number with VALUE or by cleaning the source data. |
| #NAME? | The function name is misspelled or written without the dot, for example GAMMALNPRECISE. | Type =GAMMALN.PRECISE( and let Excel's formula suggestions complete the name. |
| #N/A | A referenced cell contains #N/A from another formula, and errors pass through. | Fix the upstream formula, or wrap the whole expression in IFERROR if a fallback value is acceptable. |
Tips for using GAMMALN.PRECISE
- For positive integers n,
=GAMMALN.PRECISE(n)equals=LN(FACT(n-1)); use this as a quick sanity check. - Use GAMMALN.PRECISE instead of LN(GAMMA(x)) when x is large, because GAMMA itself may overflow.
- Remember the result is a natural log; to get the gamma value back, use
=EXP(GAMMALN.PRECISE(x)). - Keep inputs in their own cells so you can audit and change parameters without editing formulas.
- If a column may contain zeros or negatives, guard the formula with IF to avoid #NUM! errors.
Frequently asked questions
What is the difference between GAMMALN and GAMMALN.PRECISE?
Both return the natural log of the gamma function. GAMMALN.PRECISE is the newer name introduced with Excel 2010, while GAMMALN remains for backward compatibility. For normal inputs they give the same result.
Why does GAMMALN.PRECISE return an error for 0 or negative numbers?
The gamma function is not defined at zero and has poles at non-positive integers, so Excel returns #NUM! for those inputs. Supply a positive number instead.
Can I use GAMMALN.PRECISE to calculate factorials?
Yes, indirectly. For a positive integer n, the gamma function equals (n-1)!, so =EXP(GAMMALN.PRECISE(n)) gives (n-1)!. The log form is safer for large n.
Does GAMMALN.PRECISE need an add-in?
No. It is a built-in worksheet function available in every modern version of Excel.
Related functions
Every example on this page was recalculated by SheetSkill’s spreadsheet engine. GAMMALN.PRECISE reference