Special functions
Gamma function
special.gammaAlso called gamma, euler gamma function, gamma function, tgamma
Euler's integral, the continuous extension of the factorial: Γ(n) = (n − 1)! for whole n, and Γ(x + 1) = x Γ(x) for every x > 0.
Notation
the argument
x > 0
Result: the gamma function
scalar
Worked examples
Each result is solved exactly and confirmed by two independent computations.
Given
Result
Given
Result
≈ 1.77245385091
Given
Result
≈ 1.32934038818
Common mistakes
Returns x! instead of (x − 1)!
The result is Γ(x + 1) = x Γ(x), too large by a factor of x.
Fix: Γ(x) = (x − 1)!; evaluate gamma at x, or the factorial at x − 1.
Uses Stirling's approximation as the value
√(2π/x) (x/e)x is only the leading term of an asymptotic series; its relative error is about 1/(12x), already 1% at x = 8.
Fix: Use a library gamma function, or add the correction terms and shift small arguments upward first.
Source
DLMF, eq. 5.2.1
NIST Digital Library of Mathematical Functions. https://dlmf.nist.gov/ Release 1.2.8 of 2026-09-15. F. W. J. Olver, A. B. Olde Daalhuis, D. W. Lozier, B. I. Schneider, R. F. Boisvert, C. W. Clark, B. R. Miller, B. V. Saunders, H. S. Cohl, and M. A. McClain, eds.