factorialBig function

BigInt factorialBig (BigInt x)

Computes the factorial of an integer.

Implementation

BigInt factorialBig(BigInt x) {
  if (x < BigInt.zero) {
    throw ArgumentError.value(x, 'x', messages.argumentPositive);
  }

  if (x == BigInt.zero) {
    return BigInt.one;
  }

  BigInt r = x;
  while ((x -= BigInt.one) > BigInt.one) {
    r *= x;
  }

  return r;
}