Microsoft.Scripting.Utils.MathUtils.PositiveGamma C# (CSharp) Method

PositiveGamma() private static method

Computes the Gamma function on positive values, using the Lanczos approximation. Lanczos parameters are N=13 and G=13.144565.
private static PositiveGamma ( double v0 ) : double
v0 double
return double
        private static double PositiveGamma(double v0) {
            if (v0 > 200.0) {
                return Double.PositiveInfinity;
            }

            double vg = v0 + 12.644565; // v0 + g - 0.5
            double res = GammaRationalFunc(v0);
            res /= Math.Exp(vg);
            if (v0 < 120.0) {
                res *= Math.Pow(vg, v0 - 0.5);
            } else {
                // Use a smaller exponent if we're in danger of overflowing Math.Pow
                double sqrt = Math.Pow(vg, v0 / 2.0 - 0.25);
                res *= sqrt;
                res *= sqrt;
            }

            return res;
        }