# how to calculate gamma function in programming language? [duplicate]

how to calculate gamma function in programming language? I also need to support complex numbers (complex numbers are in the programming language) and negative numbers. thank you :)

-

## marked as duplicate by MJD, Trevor Wilson, Stefan Hansen, Jim, Ittay WeissMar 1 '13 at 7:53

Any particular programming language you have in mind ... ? – Zev Chonoles Mar 1 '13 at 5:04
C#, maybe C++. complex is class in those. – Lior Mar 1 '13 at 5:05
not for complex! – Lior Mar 1 '13 at 5:10

Try the Lanczos approximation.

-
what is "$g$"?<br> what is "$p_n$"?<br> @rlgordonma – Lior Mar 1 '13 at 12:42
@Lior: $g$ can be any real number, but is selected for optimum accuracy with as few terms as possible. In the Python code, they choose $g=7.0$. The $p_n$ are the coefficients defined in the article and are precomputed in the Python code for $g=7.0$. – Ron Gordon Mar 1 '13 at 13:19
how to define $p_n(x)$? – Lior Mar 1 '13 at 13:42