    Calculate the Gamma function.

gamma(z)
z - scalar or array
>>> gamma(2.3) 1.1667119051981603
>>> gamma([2.3,1.9]) array([ 1.16671191, 0.96176583])

PARAMETERS

The parameter for this function is:

Parameter
Definition
z
-171 <= z <- 171.6

The return value from this function is:

val -- The gamma function of the input.

Notes

This implementation is provided by the Cephes Math Library [1] . Arguments |x| >= 34 are reduced by recurrence and the function approximated by a rational function of degree 6/7 in the interval (2,3). Large arguments are handled by Stirling's formula. Large negative arguments are made positive using a reflection formula.

Relative errors are

domain
# trials
peak
rms
-170,33
20000
2.3e-15
3.3e-16
-33,33
20000
9.4e-16
2.2e-16
33,171.6
20000
2.3e-15
3.2e-16

Errors for arguments outside the test range will be larger owing to amplification by the exponential function.

References

[1] Cephes Math Library Release 2.0: April, 1987. Copyright 1985, 1987 by Stephen L. Moshier. Direct inquiries to 30 Frost Street, Cambridge, MA 02140.

See the bugs pages on the Sherpa website for an up-to-date listing of known bugs.

December 2023