factorial method
Returns the factorial of this BigInt.
This is the number of ways to arrange n
distinct objects into a
sequence.
Implementation
BigInt factorial() {
final n = toInt();
if (n < 0) {
throw ArgumentError('$this.factorial() is undefined.');
}
if (n < factorials.length) {
return BigInt.from(factorials[n]);
}
var r = BigInt.from(factorials.last);
for (var i = factorials.length; i <= n; i++) {
r *= BigInt.from(i);
}
return r;
}