Contact

GAMMALN Function (LibreOffice Calc)

Statistical Intermediate LibreOffice Calc

Learn the GAMMALN function in LibreOffice Calc: Returns the natural logarithm of the gamma function.

Verification status: Official documentation referenced; example outcomes independently reasoned or arithmetically checked where stated. Not executed in LibreOffice Calc. How formula examples are checked

Historical validation scope: Native observations refer to saved LibreOffice Calc 25.2.3.2 Linux evidence dated 13 October 2026 at 01:09 UTC. This later review verified all artifact hashes, all 63 formula/result pairs and eight worked-example cells, and independently recalculated the numerical examples. Calc was not rerun.

Quick answer: GAMMALN(x) returns ln(Γ(x)), the natural logarithm of the mathematical Gamma function at a positive number x. Enter:

=GAMMALN(5)

Native result: 3.17805383034795, or approximately 3.17805 to five decimal places. Because Γ(5) = 4! = 24, the same answer is LN(24). This native Calc result was checked against an independent mathematical-library calculation [N1; I1]. GAMMALN is useful in probability distributions, statistical models, logarithmic likelihoods and factorial-related calculations where intermediate Gamma values may be extremely large.

Validation scope, 13 October 2026: The online LibreOffice Help currently displays version 26.8; actual native execution for this guide used LibreOffice Calc 25.2.3.2 (Linux). Twenty-one numerical formula assertions passed against independent Python math.lgamma values or known mathematical identities. Eleven separate diagnostic cases recorded error/coercion behavior; they are observations, not version-wide guarantees or additional numerical passes. Excel and Google Sheets were not executed.

Official Calc syntax and arguments

=GAMMALN(Number)
Argument Required? Permitted mathematical domain What it means
Number Yes Positive real number (Number > 0) The numeric value x whose Gamma function logarithm is requested.

The current LibreOffice Help [S1] gives one required argument and no optional parameters, while OpenDocument 1.3 OpenFormula defines the positive-domain requirement X > 0 [S2]. The argument can be an expression (=GAMMALN(2+3)) or cell reference (=GAMMALN(A2)) containing a suitable number. In the tested English-language Calc environment, the function name is GAMMALN, a single string with no punctuation. It is distinct from the compatibility function GAMMALN.PRECISE; the names should be distinguished when checking workbook compatibility [S1].

A number exactly equal to zero or negative does not satisfy this function’s specified domain—even though the broader mathematical Gamma function has complicated behavior at some negative nonintegers. The real-valued log-Gamma function in OpenFormula is restricted to positive inputs. In Calc 25.2.3.2, tests with 0, −1 and −0.5 returned Err:502 [N1].

Understand the Gamma function before using GAMMALN

The mathematical Gamma function extends the factorial relationship from positive integers to noninteger positive inputs. For every positive integer n:

Γ(n) = (n−1)!
GAMMALN(n) = ln(Γ(n)) = ln((n−1)!)

This is a one-off indexing difference: GAMMALN(5) is LN(FACT(4)), not LN(FACT(5)). The Gamma function grows so quickly that a direct GAMMA(x) calculation can overflow the finite range of spreadsheet numbers. GAMMALN(x) is the numerically useful form of its logarithm, because it works on the logarithmic scale without requiring the enormous intermediate product [S2; N1].

For a positive noninteger, the Gamma function is not a discrete factorial, but the same log-Gamma identity still applies. For example, Γ(1/2)=√π; therefore GAMMALN(1/2)=(1/2)*LN(PI()), approximately 0.5723649429247 in native Calc 25.2.3.2 [N1].

Important: GAMMALN computes the natural logarithm of Γ(x), not log base 10, not LN(x), and not LN(GAMMA(x+1)) unless you intentionally want the factorial of x.

A reproducible worksheet: integer factorial relationship

Enter these values into a clean Calc sheet. The saved native workbook records the corresponding calculation [N1].

Cell Enter Explanation
A2 5 Gamma argument; positive integer
B2 =GAMMALN(A2) Requested log-Gamma result
C2 =LN(FACT(A2-1)) Independent factorial identity using Calc functions
D2 =B2-C2 Difference; should be approximately zero

Expected B2 and C2: approximately 3.17805383034795; D2: zero or a floating-point residual at machine precision. The saved .ods workbook has its own sample at E10:E13 on the Reader examples sheet and a validation matrix of native formulas. The independently computed Python reference for x=5 was 3.178053830347945 [I1].

For a second manual test, enter =GAMMALN(3). The answer is 0.693147180559945, because Γ(3) = 2! = 2 and LN(2) has this value. LibreOffice Help also demonstrates =GAMMALN(2) returning zero, since Γ(2)=1 [S1]. Both results were observed natively [N1].

Native-tested formulas and expected outputs

These examples were executed in Calc 25.2.3.2 and checked against independent math.lgamma(x) or exact mathematical identities [N1; I1]. The displayed decimal digits are rounded representations; Calc stores finite-precision numeric values.

Formula Native result (approximately) Reason
=GAMMALN(0.5) 0.5723649429247 Γ(1/2) = √π
=GAMMALN(1) 0 Γ(1) = 1
=GAMMALN(1.5) −0.120782237635245 Γ(1.5) is below 1, so its natural log is negative
=GAMMALN(2) 0 Γ(2) = 1! = 1
=GAMMALN(3) 0.693147180559945 LN(2!)
=GAMMALN(4) 1.79175946922806 LN(3!) = LN(6)
=GAMMALN(5) 3.17805383034795 LN(4!) = LN(24)
=GAMMALN(10) 12.8018274800815 LN(9!)
=GAMMALN(100) 359.134205369575 Large positive argument without direct factorial
=GAMMALN(200) 857.933669825857 Direct GAMMA(200) can exceed floating-point range
=GAMMALN(500) 2605.11585036173 A very large log-Gamma value computed natively

The sometimes surprising negative GAMMALN(1.5) result is valid. The function returns a logarithm; the Gamma value Γ(1.5) is positive but less than 1, making the natural log negative. A negative result is not evidence that the positive input domain was violated. Distinguish this from passing a negative input, which is outside the OpenFormula domain.

Advanced example 1: compute log combinations without factorial overflow

Suppose you need the logarithm of a binomial coefficient, “n choose k,” which arises in discrete probability models:

ln(C(n,k)) = GAMMALN(n+1) − GAMMALN(k+1) − GAMMALN(n−k+1)

For n=100 and k=50, enter:

=GAMMALN(101)-GAMMALN(51)-GAMMALN(51)

The result is approximately 66.7838416520 (independently calculated using Python math.lgamma, not a separate native assertion for this combined formula). Why use the logs? The factorials of 100 and 50 are large but finite in ordinary double precision; larger factorial arguments can overflow, and direct products can introduce rounding error. The log form is practical for likelihood calculations and ratio comparisons. If you want the coefficient itself, an EXP(...) may still overflow for large combinations; preserve the logarithmic result when using it in larger statistical models.

More generally, if the number of groups is large and you want stable log probabilities, sum and subtract GAMMALN terms before applying EXP to any final probability that is safe to exponentiate. Be aware that differences of large nearly equal values can still lose precision due to subtraction.

Advanced example 2: gamma-distribution log density

For a gamma distribution parameterized by shape α>0, scale θ>0, evaluated at x>0, the logarithm of the density is:

log f(x;α,θ) = (α−1)·ln(x) − x/θ − α·ln(θ) − ln Γ(α)

With x in A2, shape in B2, and scale in C2, this is:

=(B2-1)*LN(A2)-A2/C2-B2*LN(C2)-GAMMALN(B2)

For example, when x=3, shape α=2 and scale θ=2, the result is LN(3)-3/2-2*LN(2)-GAMMALN(2), about −1.78768207245. This is an independent mathematical derivation, not a separately executed native formula assertion. GAMMALN(2)=0 was natively tested; the combined formula should be reproduced with an actual input sheet before use in production analysis.

This approach helps when multiplying many small probability densities would underflow. Addition of log densities is typically more stable than multiplying unlogged densities. Distinguish scale from rate parameterization; if you have a rate instead, the formula changes. Do not use this expression with invalid x, shape or scale.

Advanced example 3: factorial-like operations and large numbers

For a positive integer n, the logarithm of n! is:

=GAMMALN(n+1)

If n is in A2:

=GAMMALN(A2+1)

For n=4 the answer is 3.17805383034795, equal to LN(FACT(4)). This is a useful bridge between exact combinatorics and statistical models. For larger values, calculate on the log scale and avoid directly converting back to enormous factorial values.

The mathematical recurrence Γ(x+1) = x·Γ(x) yields another way to check your work for positive x:

GAMMALN(x+1) = LN(x) + GAMMALN(x)

For x=4, this becomes GAMMALN(5) = LN(4) + GAMMALN(4). The relation follows from Gamma mathematics [S2]; it should be used as a mathematical cross-check, not a claim that two implementations are bit-for-bit identical at all inputs.

How it differs from GAMMA, GAMMALN.PRECISE, LN and FACT

Function What it calculates Important caution
GAMMA The Gamma function itself, Γ(x) Results can overflow even if GAMMALN(x) is finite.
GAMMALN The natural logarithm ln(Γ(x)) for positive x The documented standard function on this page.
GAMMALN.PRECISE The natural logarithm of Gamma in an additional interoperability function LibreOffice Help says introduced in 4.3 and names an extension namespace, COM.MICROSOFT.GAMMALN.PRECISE; not part of OpenFormula 1.3 [S1].
LN Natural logarithm of the input number LN(x) and GAMMALN(x) are different, except in particular coincidences.
FACT n! for a whole-number case GAMMALN(n+1) is the log of n!, not the direct factorial.

In native Calc 25.2.3.2, =GAMMALN(4)-GAMMALN.PRECISE(4) returned 0 in a tested numeric comparison. This does not prove their results are identical for every input or product version [N1]. If round-tripping ODF through Excel/Google Sheets, verify which function name and namespace are persisted in the file and whether the target engine understands it.

Positive domain, text handling and native error observations

For these diagnostic cases, the expectation is not an independent numerical result. They were observed in Calc 25.2.3.2 [N1]. A vendor change or locale may display errors differently.

Test formula Native observation Reader action
=GAMMALN(0) Err:502 Input must be strictly greater than zero [S2].
=GAMMALN(-1) Err:502 Reject negative inputs; even Gamma’s analytic continuation is not this real-valued function’s domain.
=GAMMALN(-0.5) Err:502 The OpenFormula positive-domain rule still applies.
=GAMMALN("bad") #VALUE! Convert or correct invalid text.
=GAMMALN("5") 3.17805383034795 Direct numeric text was coerced successfully in this native test, but do not assume text import always behaves identically.
=GAMMALN() Err:511 Provide one positive numeric argument.
=GAMMALN(TRUE()) 0 Native TRUE was effectively treated as 1 in this single observed case; prefer explicit numbers.
=GAMMALN(F5) where F5 truly blank Err:502 Blank cell references may act as zero; require positive numeric input.
=GAMMALN(F4) where F4 contains text #VALUE! Validate imported numeric cells rather than trusting their formatting.
=GAMMALN(C3:C5) in an ordinary scalar formula #VALUE! Supply one numeric value for a scalar call; do not assume range handling without an array-specific design.
=GAMMALN(0.001) 6.90717888538385 Small positive x is valid even when the result is large.

To guard a user-facing sheet against invalid numeric values, a possible precondition is:

=IF(AND(ISNUMBER(A2);A2>0);GAMMALN(A2);"Enter a positive number")

This validation formula is an instructional recommendation not separately executed in the saved native workbook. ISNUMBER checks that the input is numeric and A2>0 checks the documented domain. Upstream error values can still propagate. For mixed input data, validate cell types on import rather than automatically coercing everything.

Precision, stability and limitations

GAMMALN is often more stable for large positive arguments than LN(GAMMA(x)) because the latter must first materialize the huge Γ(x). Native Calc calculations produced finite GAMMALN(200) ≈ 857.933669826 and GAMMALN(500) ≈ 2605.115850362, agreeing with independent math.lgamma [N1; I1]. The number of decimals displayed is not a guarantee that every digit is precise for every argument. Floating-point rounding, convergence methods or implementation changes can affect the last digits, especially near sensitive regions.

Other precautions: never call GAMMALN for nonpositive real inputs under the ODF specification; do not interpret a negative output as a domain failure; remember the factorial shift by one; keep input units/shape parameters dimensionless where mathematically required; and do not convert large log values with EXP unless the resulting number can fit the engine’s floating-point range.

This is not a probability function by itself. A valid probability density formula may use GAMMALN inside it, but the returned log-Gamma has no direct interpretation as a probability between zero and one.

Locale and compatibility

LibreOffice Help and OpenFormula use the English function name GAMMALN. This function takes one argument, so a changed argument separator is not usually an issue; decimal separators can still differ by locale (e.g., 0.5 vs 0,5). Enter values in separate cells if you exchange workbooks internationally. For the extension GAMMALN.PRECISE, LibreOffice Help expressly documents its COM.MICROSOFT.GAMMALN.PRECISE namespace rather than standard OpenFormula membership [S1].

Excel has a similarly named logarithmic Gamma function, and other spreadsheet products may expose corresponding functions, but this review did not execute those products. Similar names do not justify promising equal text conversions, error labels, numerical precision or file-format mapping. Check the relevant target-product documentation and execute a compatibility workbook before relying on portability.

Frequently asked questions

Why is GAMMALN(5) not LN(120)?

Because Γ(5) is (5−1)! = 4! = 24, not 5!. Therefore GAMMALN(5)=LN(24)≈3.17805. For LN(120) instead, calculate GAMMALN(6), because Γ(6)=5!=120 [S2; N1].

Can GAMMALN return a negative result?

Yes. The native-tested value for GAMMALN(1.5) is approximately −0.120782237635245, because Γ(1.5) lies between zero and one. That is a mathematically valid logarithm; input x=1.5 is positive [N1].

Should I always use GAMMALN.PRECISE instead?

No categorical recommendation follows from the available evidence. Calc 25.2.3.2 produced matching results for an ordinary positive test input, but official Help identifies GAMMALN.PRECISE as a separate interoperability function, added in LibreOffice 4.3, and not part of ODF OpenFormula 1.3 [S1]. Choose based on the target workbook’s expectations and test representative inputs in the target version.

Is it safe to use GAMMALN for big factorials?

For positive arguments, the log form avoids forming gigantic intermediate factorials. The native tests at 100, 200 and 500 agreed with independent math.lgamma checks; do not interpret that as arbitrary-precision arithmetic [N1].

Is GAMMALN the Gamma probability distribution?

No. GAMMALN is the logarithm of the Gamma function, a mathematical building block. Gamma probability density or cumulative distribution functions have additional parameters and formulas. Use the appropriate function for probabilities, not GAMMALN alone.

Dated official references and evidence classification

Reviewed 13 October 2026. Claim-level sources:

  • [S1] LibreOffice Calc Help 26.8, “Statistical Functions Part Two — GAMMALN / GAMMALN.PRECISE.” https://help.libreoffice.org/latest/en-US/text/scalc/01/04060182.html . Confirms GAMMALN(Number), example result for 2, and the distinct GAMMALN.PRECISE function since LibreOffice 4.3 with COM.MICROSOFT.GAMMALN.PRECISE interoperability namespace. “Latest” displayed 26.8 at checking; version 26.8 was not executed.
  • [S2] OASIS OpenDocument 1.3, Part 4: Recalculated Formula (OpenFormula), GAMMALN definition. https://docs.oasis-open.org/office/OpenDocument/v1.3/cs02/part4-formula/OpenDocument-v1.3-cs02-part4-formula.html . Specifies GAMMALN(Number X), domain X>0, and the natural log of positive Gamma, with GAMMALN.PRECISE absent from this standard name list.
  • [N1] Native LibreOffice Calc 25.2.3.2 (Linux) execution: FVSCHEDULE_GAMMALN_native_validation.ods and native_validation_results.json in the saved dated evidence, with all 21/21 GAMMALN numeric comparisons passed plus eleven independent diagnostic observations.
  • [I1] Independent calculations: run_native_fvschedule_gammaln.py uses Python math.lgamma and factorial identities independently from Calc for expected values. Tolerances are relative 5e-11, absolute 3e-10. This was not an independent execution of Excel or Google Sheets.