factorialD function

double factorialD(
  1. int x
)

Computes the factorial function x -> x! of an integer number > 0. The function can represent all number up to 22! exactly, all numbers up to 170! using a double representation. All larger values will overflow.

If you need to multiply or divide various such factorials, consider using the logarithmic version factorialLn instead so you can add instead of multiply and subtract instead of divide, and then exponentiate the result using exp. This will also circumvent the problem that factorials become very large even for small parameters.

Implementation

double factorialD(int x) {
  if (x < 0) {
    throw ArgumentError.value(x, 'x', messages.argumentPositive);
  }

  if (x < _factorialCache.length) {
    return _factorialCache[x];
  }

  return double.infinity;
}