pub const fn factorial(n: usize) -> u128
Expand description

return n! (n factorial).

Panic

It overflows if n >= 35 and panics in debug.

Example

assert_eq!(factorial(0), 1);
assert_eq!(factorial(4), 24);
assert_eq!(factorial(6), 720);
assert_eq!(factorial(34), 295232799039604140847618609643520000000);
let n = factorial(34);
let (_, overflowed) = n.overflowing_mul(35); // try compute 35! with overflow check.
assert!(!overflowed);