Trait factorial::Factorial

source ·
pub trait Factorial<Target = Self> {
    // Required methods
    fn checked_factorial(&self) -> Option<Target>;
    fn psw_factorial(&self, sieve: &Sieve) -> Option<Target>;

    // Provided method
    fn factorial(&self) -> Target { ... }
}
Expand description

Unary operator for computing the factorial of a number

Implements checked and unchecked versions of the formula

Required Methods§

source

fn checked_factorial(&self) -> Option<Target>

Returns self!, i.e. the factorial of self, if it doesn’t overflow the type T.

Examples
use factorial::Factorial;
assert_eq!(10u32.checked_factorial(), Some(3628800));
source

fn psw_factorial(&self, sieve: &Sieve) -> Option<Target>

Returns self!, i.e. the factorial of self using the prime swing algorithm.

Examples
use factorial::Factorial;
use primal_sieve::Sieve;
// The sieve must be equal or greater than the argument of the factorial.
let sieve = Sieve::new(10_usize);
assert_eq!(10_usize.factorial(), 3628800);

Provided Methods§

source

fn factorial(&self) -> Target

Returns self!, i.e. the factorial of self.

Examples
use factorial::Factorial;
assert_eq!(10u32.factorial(), 3628800);

Implementors§