permutations function Null safety

double permutations(
  1. double n,
  2. double k,
  3. {double initial = 1}
)

Implementation

double permutations(double n, double k, {double initial = 1}) {
  if (n < 0 ||
      k < 0 ||
      k > n ||
      n != n.floorToDouble() ||
      k != k.floorToDouble()) {
    throw CalculatorError(0);
  } else if (k > 70) {
    return double.infinity;
  } else if (n - k <= 1) {
    return factorial(n);
  }
  double result = initial;
  for (int i = (n - k).floor() + 1; i <= n.floor(); i++) {
    result *= i;
  }
  return result;
}