How the Gamma Function Works
The gamma function Γ(x) generalizes the factorial to real (and complex) numbers. For a positive integer n, Γ(n) equals (n-1)!, but Γ(x) is also defined for fractional and negative non-integer x, giving a smooth curve that passes through every factorial value. This calculator evaluates Γ(x) using the Lanczos approximation, a fast numerical method that reproduces the true value of the gamma function to about 15 significant digits.
The integral definition
For x > 0, the gamma function is defined by the improper integral Γ(x) = ∫₀^∞ t^(x-1) e^(-t) dt. This integral converges for every positive x. Because direct numerical integration is slow and loses precision for large x, this calculator instead uses the Lanczos approximation — a rational-function formula tuned to match Γ(x) to double-precision accuracy without evaluating the integral directly.
Recurrence relation and factorials
The gamma function satisfies the recurrence Γ(x+1) = x · Γ(x). Applying this repeatedly to a positive integer n shows Γ(n+1) = n · (n-1) · … · 1 · Γ(1) = n!, since Γ(1) = 1. So Γ(6) = 5! = 120, Γ(1) = 0! = 1, and so on — the factorial you learned in school is just the gamma function evaluated at integer-plus-one arguments.
Reflection formula and negative arguments
For non-integer x < 0.5, this calculator uses the reflection formula Γ(x) · Γ(1-x) = π / sin(πx) to compute Γ(x) from Γ(1-x), which lies in the well-behaved positive range. This is also why Γ(x) is undefined at x = 0, -1, -2, -3, …: sin(πx) = 0 at every integer, so the reflection formula would require dividing by zero, producing a pole (the function value shoots to ±infinity as x approaches these points from either side).