Skip to content
Math

Gamma Function Calculator - Compute Gamma(x) with Steps

Enter any real number x and get the exact value of Gamma(x), the natural log of the Gamma function, the reciprocal 1/Gamma(x), and (where applicable) the equivalent factorial. The calculator handles positive values, negative non-integers, half-integers, and large arguments using the Lanczos approximation. A step-by-step panel explains the method used for your specific input.

Your details

Enter any real number. Gamma is undefined at 0 and negative integers (poles). Try 0.5 for sqrt(pi), or a positive integer n to get (n-1)!
Gamma(x)Positive value
24

The Gamma function evaluated at x

ln|Gamma(x)|3.1780538
1 / Gamma(x)0.041666667
Factorial equivalent(5 - 1)! = 4! = 24
Input typePositive integer - exact factorial
-33.9443.03120-136
x
  • Gamma(x) for x in (0.5, 6)
  • Gamma(x) for x in (-1, 0)

Gamma(5) = 24

  • For positive integers, Gamma(n) = (n - 1)!, so Gamma(5) = 4!
  • This is the key link between the Gamma function and ordinary factorials.
  • The natural log of |Gamma(5)| is 3.1780538, useful for avoiding overflow with large values.

Next stepTry x = 5.5 (a half-integer) to see Gamma at a non-integer point.

What is the Gamma function?

The Gamma function, written Gamma(x), is a continuous generalization of the factorial function to all real (and complex) numbers except the non-positive integers. It was introduced by Leonhard Euler in the 18th century to answer the question: what does n! mean when n is not a whole number? The defining integral is Gamma(x) = integral from 0 to infinity of t^(x-1) * e^(-t) dt, which converges for all x > 0. For positive integers n, this gives Gamma(n) = (n-1)!, so Gamma(5) = 24 = 4!. The function then extends to negative non-integers via the reflection formula or the recurrence relation Gamma(x+1) = x*Gamma(x).

The factorial connection and special values

The most important property of the Gamma function is the recurrence Gamma(x+1) = x*Gamma(x), which means each value determines the next. For positive integers this collapses to ordinary factorials: Gamma(1) = 1, Gamma(2) = 1, Gamma(3) = 2, Gamma(4) = 6, and so on. The half-integer values are equally celebrated: Gamma(1/2) = sqrt(pi), Gamma(3/2) = sqrt(pi)/2, Gamma(5/2) = 3*sqrt(pi)/4. These arise constantly in probability: the normal distribution, the chi-squared distribution, and the beta distribution all involve Gamma(1/2) = sqrt(pi). The fact that Gamma(1/2) equals the square root of pi connects factorial arithmetic to the geometry of circles and the Gaussian integral.

Negative values and poles

The Gamma function is defined for all real x except 0, -1, -2, -3, ..., where it has simple poles (the value diverges to infinity). Between each pair of consecutive negative integer poles the function is finite and alternates sign: it is negative between 0 and -1, positive between -1 and -2, negative between -2 and -3, and so on. This sign alternation comes from applying the reflection formula Gamma(x)*Gamma(1-x) = pi/sin(pi*x), which relates Gamma at x to Gamma at 1-x. The reciprocal function 1/Gamma(x) is entire (finite and smooth everywhere), equal to zero at the poles, and is sometimes more convenient to work with.

Numerical computation: Lanczos approximation

Computing Gamma(x) to machine precision requires a carefully chosen approximation. This calculator uses the Lanczos approximation with g = 7 and 9 coefficients, which achieves about 15 significant digits of accuracy for all x with positive real part, well within IEEE 754 double precision. For x < 0.5, the reflection formula redirects the computation to the positive half-plane where Lanczos works best. The natural log of the Gamma function, ln|Gamma(x)|, is computed directly from the Lanczos formula before exponentiating, which avoids overflow for large arguments - Gamma(171) overflows a 64-bit float, but ln|Gamma(171)| does not. If you are working with very large arguments, use the ln|Gamma| result and work in log-space.

Key Gamma function values

xGamma(x)Notes
-1.52.363272...Negative non-integer (reflection formula)
-0.5-3.544907...Negative non-integer - equals -2*sqrt(pi)
0undefinedPole
0.51.772453...sqrt(pi) - famous special value
110! = 1
1.50.886226...sqrt(pi)/2
211! = 1
322! = 2
463! = 6
5244! = 24
61205! = 120
103628809! = 362880
171overflowBeyond double precision (use ln|Gamma| instead)

Special and integer values of Gamma(x). For positive integers n, Gamma(n) = (n-1)!. Half-integer values involve sqrt(pi).

Frequently asked questions

What is Gamma(0.5)?

Gamma(1/2) = sqrt(pi), approximately 1.772453850905516. This is one of the most famous values in mathematics: it links the factorial generalization to pi via the Gaussian integral. All half-integer Gamma values can be expressed in terms of sqrt(pi) using the recurrence Gamma(x+1) = x*Gamma(x).

Why is Gamma(n) = (n-1)! and not n!?

Euler defined the integral representation so that it satisfies Gamma(1) = 1 and Gamma(x+1) = x*Gamma(x). Plugging in integer n gives Gamma(2) = 1*Gamma(1) = 1 = 1!, Gamma(3) = 2*Gamma(2) = 2 = 2!, Gamma(4) = 6 = 3!, and so on. The shift of one is a historical convention. Some authors instead define Pi(n) = Gamma(n+1) = n! to avoid the off-by-one.

What happens at x = 0, -1, -2, ...?

The Gamma function has simple poles at all non-positive integers. The function grows without bound as x approaches any of these values from either side. The value is genuinely undefined, not infinity in any meaningful sense. However, the reciprocal 1/Gamma(x) is smooth and equal to zero at every pole, which is why many formulas use 1/Gamma instead of Gamma to avoid worrying about these special points.

How accurate is this calculator?

The Lanczos approximation used here achieves roughly 15 significant digits of accuracy, matching the precision of IEEE 754 double-precision floating-point arithmetic. This is more than sufficient for virtually all scientific and engineering applications. For x close to the poles at 0 and the negative integers, the reciprocal 1/Gamma(x) remains well-conditioned even where Gamma(x) itself is extremely large.

What is the Gamma function used for?

The Gamma function appears throughout mathematics and its applications. In probability and statistics it defines the gamma distribution, the beta distribution, the chi-squared distribution, and the Student t-distribution. In physics it appears in quantum mechanics, statistical mechanics, and string theory. In combinatorics it generalizes binomial coefficients to non-integer arguments. It is also central to the Riemann zeta function, the digamma function, and many hypergeometric series.

What is ln|Gamma(x)| and when should I use it?

The natural log of the absolute value of Gamma(x) stays finite even for very large arguments where Gamma(x) itself overflows double-precision floating point (beyond about x = 171). When computing ratios or products involving Gamma, work in log-space: compute ln|Gamma(a)| + ln|Gamma(b)| - ln|Gamma(a+b)| rather than Gamma(a)*Gamma(b)/Gamma(a+b), then exponentiate only at the end. This avoids both overflow and underflow.

Sources

Written by Dr. Rajiv Menon, PhD Applied Mathematician · Bengaluru, India

Applied mathematician bridging algebraic theory and computational tools for students, engineers, and everyday problem-solvers.

Search 3,500+ calculators

Loading search…