gamma

sherpa.utils.gamma(z)[source] [edit on github]

Calculate the Gamma function.

Parameters:

z (scalar or array) – -171 <= z <- 171.6

Returns:

val – The gamma function of the input.

Return type:

scalar or array

See also

igam, lgam

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

Examples

>>> gamma(2.3)
1.1667119051981603
>>> gamma([2.3,1.9])
array([ 1.16671191,  0.96176583])