Skip to main content

factorial

Function factorial 

Source
pub const fn factorial(n: u64) -> Result<u128, CombinatoricsError>
Expand description

Returns n! using checked u128 arithmetic.

Overflow begins at n = 35.

§Errors

Returns CombinatoricsError::FactorialOverflow when the result no longer fits in u128.

§Examples

use use_combinatorics::factorial;

assert_eq!(factorial(5)?, 120);
Examples found in repository?
examples/facade_combinatorics.rs (line 4)
3fn main() -> Result<(), use_math::CombinatoricsError> {
4    assert_eq!(factorial(5)?, 120);
5    assert_eq!(permutations(5, 3)?, 60);
6    assert_eq!(combinations(5, 2)?, 10);
7
8    Ok(())
9}