Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

The question is simple. I would like to implement the Gamma function in my calculator written in C; however, I have not been able to find an easy way to programmatically compute an approximation to arbitrary precision.

Is there a good algorithm to compute approximations of the Gamma function?


share|improve this question
Do you want an algorithm for its complex domain or just for real numbers? –  Gerben Jan 27 '11 at 15:39
complex would be better –  houbysoft Jan 27 '11 at 15:47
For reals it in is the GNU C library (haven't checked if it is mandated by the standard). –  vonbrand Mar 1 '13 at 16:07
@vonbrand: not to arbitrary precision, though. –  houbysoft Jan 8 '14 at 10:19

5 Answers 5

up vote 5 down vote accepted

Looks like the Lanczos approximation will suit my needs : http://en.wikipedia.org/wiki/Lanczos_approximation

Thanks for your help!

share|improve this answer
This note should be of interest. –  J. M. Jul 27 '11 at 9:49

Someone asked a similar question yesterday. I thought of replacing $e^{-t}$ by a series. $$\Gamma (z) = \int_{0}^{\infty} t^{z-1} e^{-t} dt \approx \sum_{j=0}^{a} \frac{(-1)^j b^{j+z}}{(j + z) j !} . \text{Choose } a > b ,$$ but as J. M. points out, I should have checked this a bit better. Take great care in the choice of $a, b$.

share|improve this answer
Have you tried implementing this? :) –  J. M. Oct 9 '11 at 10:17
Not with more than one $z$. It can be very inaccurate depending on the choice of $a, b$. Now that I've tried a few more $z$, it looks like $a = b z^2$ is about right, but $b$ must also be chosen not too far from $z$. Example: $z = 6.6$, $b=2 \times z$, $a = b z^2$. This is only a guess! –  Samuel Hambleton Oct 9 '11 at 11:32

It is now part of the C++11 standard library.


share|improve this answer
What you link to is the C++ interface to the standard C library. –  vonbrand Mar 1 '13 at 16:09
This is not to arbitrary precision, though. –  houbysoft Jan 8 '14 at 10:19

How about interpolation of the numbers in a look-up table featuring numbers drawn from a graph of the curve you are looking for? If you have the program Stella, you can literally shape by hand a curve that you desire, and it produces the numbers to be added to the table.

share|improve this answer
The domain of the Gamma function is the entire complex plane. You cannot use a lookup table for functions like this. –  user11393 Jan 28 '13 at 9:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.