MathPHP\Probability\Combinatorics::fallingFactorial PHP Метод

fallingFactorial() публичный статический Метод

https://en.wikipedia.org/wiki/Falling_and_rising_factorials x₍ᵢ₎ = x * (x - 1) * (x - 2) ... (x - i + 1)
public static fallingFactorial ( number $x, integer $n ) : number
$x number
$n integer
Результат number
    public static function fallingFactorial($x, int $n)
    {
        if ($n < 0) {
            throw new Exception\OutOfBoundsException('Cannot compute rising factorial of a negative number.');
        }
        if ($n > $x) {
            return 0;
        }
        $fact = 1;
        while ($n > 0) {
            $fact *= $x - $n + 1;
            $n--;
        }
        return $fact;
    }