Created
February 28, 2012 17:16
-
-
Save prashantvc/1933772 to your computer and use it in GitHub Desktop.
Gamma function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
double Gamma(double x) | |
{ | |
if (x < 0) | |
{ | |
return double.PositiveInfinity; | |
} | |
// Gamma(x) = (x-1)! so add 1, to make user gets | |
// expected result, I really don't want use increamental operator here. | |
x += 1; | |
double p1 = Math.Sqrt(2 * Math.PI / x); | |
double p2 = x + 1.0 / (12 * x - 1.0 / (10 * x)); | |
p2 = Math.Pow(p2 / Math.E, x); | |
return Math.Round(p1 * p2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment