calculateRising static method

BigInt calculateRising(
  1. int x,
  2. int n
)

Calculates the rising factorial (Pochhammer symbol) of x to the power of n.

The rising factorial, denoted by x^(n) or (x)n, is defined as the product of n terms, starting with x and each successive term increasing by 1.

Definition: x^(n) = x * (x+1) * (x+2) * ... * (x+n-1)

  • If n = 0, x^(0) = 1 (this is an empty product).

Parameters:

  • x: The starting number (can be any integer).
  • n: The number of terms to multiply (must be a non-negative integer).

Returns: A BigInt representing the rising factorial of x to n.

Throws:

Implementation

static BigInt calculateRising(int x, int n) {
  if (n < 0) {
    throw ArgumentError('Rising factorial is not defined for negative n.');
  }

  if (n == 0) return BigInt.one;
  var result = BigInt.from(x);

  for (int i = 0; i < n; i++) {
    result *= BigInt.from(x + i);
  }

  return result;
}