public static function gammaStirling($n)
{
// Basic integer/factorial cases
if ($n == 0) {
return \INF;
}
// Negative integer, or negative int as a float
if ((is_int($n) || is_numeric($n) && abs($n - round($n)) < 1.0E-5) && $n < 0) {
return -\INF;
}
// Positive integer, or postive int as a float
if ((is_int($n) || is_numeric($n) && abs($n - round($n)) < 1.0E-5) && $n > 0) {
return Combinatorics::factorial(round($n) - 1);
}
// Compute parts of equation
$√2π = sqrt(2 * \M_PI);
$ℯ⁻ⁿ = exp(-$n);
$√1/n = sqrt(1 / $n);
$⟮n + 1/⟮12n − 1/10n⟯⟯ⁿ = pow($n + 1 / (12 * $n - 1 / (10 * $n)), $n);
/**
* Put it all together:
* ___
* __ / 1 / 1 \ n
* Γ(n)≈ √2π ℯ⁻ⁿ / - | n + ----------- |
* √ n \ 12n - 1/10n /
*/
return $√2π * $ℯ⁻ⁿ * $√1/n * $⟮n + 1/⟮12n − 1/10n⟯⟯ⁿ;
}