pub trait CheckedFactorial: Sized {
// Required method
fn checked_factorial(n: u64) -> Option<Self>;
}
Expand description
Computes the factorial of a u64
, returning None
if the result is too large to be
represented.
Required Methods§
fn checked_factorial(n: u64) -> Option<Self>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl CheckedFactorial for u8
impl CheckedFactorial for u8
Source§fn checked_factorial(n: u64) -> Option<u8>
fn checked_factorial(n: u64) -> Option<u8>
Computes the factorial of a number.
If the input is too large, the function returns None
.
$$
f(n) = \begin{cases}
\operatorname{Some}(n!) & \text{if} \quad n! < 2^W, \\
\operatorname{None} & \text{if} \quad n! \geq 2^W,
\end{cases}
$$
where $W$ is Self::WIDTH
.
$n! = O(\sqrt{n}(n/e)^n)$.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl CheckedFactorial for u16
impl CheckedFactorial for u16
Source§fn checked_factorial(n: u64) -> Option<u16>
fn checked_factorial(n: u64) -> Option<u16>
Computes the factorial of a number.
If the input is too large, the function returns None
.
$$
f(n) = \begin{cases}
\operatorname{Some}(n!) & \text{if} \quad n! < 2^W, \\
\operatorname{None} & \text{if} \quad n! \geq 2^W,
\end{cases}
$$
where $W$ is Self::WIDTH
.
$n! = O(\sqrt{n}(n/e)^n)$.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl CheckedFactorial for u32
impl CheckedFactorial for u32
Source§fn checked_factorial(n: u64) -> Option<u32>
fn checked_factorial(n: u64) -> Option<u32>
Computes the factorial of a number.
If the input is too large, the function returns None
.
$$
f(n) = \begin{cases}
\operatorname{Some}(n!) & \text{if} \quad n! < 2^W, \\
\operatorname{None} & \text{if} \quad n! \geq 2^W,
\end{cases}
$$
where $W$ is Self::WIDTH
.
$n! = O(\sqrt{n}(n/e)^n)$.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl CheckedFactorial for u64
impl CheckedFactorial for u64
Source§fn checked_factorial(n: u64) -> Option<u64>
fn checked_factorial(n: u64) -> Option<u64>
Computes the factorial of a number.
If the input is too large, the function returns None
.
$$
f(n) = \begin{cases}
\operatorname{Some}(n!) & \text{if} \quad n! < 2^W, \\
\operatorname{None} & \text{if} \quad n! \geq 2^W,
\end{cases}
$$
where $W$ is Self::WIDTH
.
$n! = O(\sqrt{n}(n/e)^n)$.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl CheckedFactorial for u128
impl CheckedFactorial for u128
Source§fn checked_factorial(n: u64) -> Option<u128>
fn checked_factorial(n: u64) -> Option<u128>
Computes the factorial of a number.
If the input is too large, the function returns None
.
$$
f(n) = \begin{cases}
\operatorname{Some}(n!) & \text{if} \quad n! < 2^W, \\
\operatorname{None} & \text{if} \quad n! \geq 2^W,
\end{cases}
$$
where $W$ is Self::WIDTH
.
$n! = O(\sqrt{n}(n/e)^n)$.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl CheckedFactorial for usize
impl CheckedFactorial for usize
Source§fn checked_factorial(n: u64) -> Option<usize>
fn checked_factorial(n: u64) -> Option<usize>
Computes the factorial of a usize
.
If the input is too large, the function returns None
.
$$
f(n) = \begin{cases}
\operatorname{Some}(n!) & \text{if} \quad n! < 2^W, \\
\operatorname{None} & \text{if} \quad n! \geq 2^W,
\end{cases}
$$
where $W$ is usize::WIDTH
.
$n! = O(\sqrt{n}(n/e)^n)$.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.