Trait malachite_base::num::arithmetic::traits::DoubleFactorial
source · pub trait DoubleFactorial {
// Required method
fn double_factorial(n: u64) -> Self;
}
Expand description
Computes the double factorial of a u64
. The double factorial of a non-negative integer is the
product of all the positive integers that are less than or equal to it and have the same parity
as it.
Required Methods§
fn double_factorial(n: u64) -> Self
Object Safety§
Implementations on Foreign Types§
source§impl DoubleFactorial for u8
impl DoubleFactorial for u8
source§fn double_factorial(n: u64) -> u8
fn double_factorial(n: u64) -> u8
Computes the double factorial of a number.
If the input is too large, the function panics. For a function that returns None
instead, try
checked_double_factorial
.
$$ f(n) = n!! = n \times (n - 2) \times (n - 4) \times \cdots \times i, $$ where $i$ is 1 if $n$ is odd and $2$ if $n$ is even.
$n!! = O(\sqrt{n}(n/e)^{n/2})$.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the output is too large to be represented.
§Examples
See here.
source§impl DoubleFactorial for u16
impl DoubleFactorial for u16
source§fn double_factorial(n: u64) -> u16
fn double_factorial(n: u64) -> u16
Computes the double factorial of a number.
If the input is too large, the function panics. For a function that returns None
instead, try
checked_double_factorial
.
$$ f(n) = n!! = n \times (n - 2) \times (n - 4) \times \cdots \times i, $$ where $i$ is 1 if $n$ is odd and $2$ if $n$ is even.
$n!! = O(\sqrt{n}(n/e)^{n/2})$.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the output is too large to be represented.
§Examples
See here.
source§impl DoubleFactorial for u32
impl DoubleFactorial for u32
source§fn double_factorial(n: u64) -> u32
fn double_factorial(n: u64) -> u32
Computes the double factorial of a number.
If the input is too large, the function panics. For a function that returns None
instead, try
checked_double_factorial
.
$$ f(n) = n!! = n \times (n - 2) \times (n - 4) \times \cdots \times i, $$ where $i$ is 1 if $n$ is odd and $2$ if $n$ is even.
$n!! = O(\sqrt{n}(n/e)^{n/2})$.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the output is too large to be represented.
§Examples
See here.
source§impl DoubleFactorial for u64
impl DoubleFactorial for u64
source§fn double_factorial(n: u64) -> u64
fn double_factorial(n: u64) -> u64
Computes the double factorial of a number.
If the input is too large, the function panics. For a function that returns None
instead, try
checked_double_factorial
.
$$ f(n) = n!! = n \times (n - 2) \times (n - 4) \times \cdots \times i, $$ where $i$ is 1 if $n$ is odd and $2$ if $n$ is even.
$n!! = O(\sqrt{n}(n/e)^{n/2})$.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the output is too large to be represented.
§Examples
See here.
source§impl DoubleFactorial for u128
impl DoubleFactorial for u128
source§fn double_factorial(n: u64) -> u128
fn double_factorial(n: u64) -> u128
Computes the double factorial of a number.
If the input is too large, the function panics. For a function that returns None
instead, try
checked_double_factorial
.
$$ f(n) = n!! = n \times (n - 2) \times (n - 4) \times \cdots \times i, $$ where $i$ is 1 if $n$ is odd and $2$ if $n$ is even.
$n!! = O(\sqrt{n}(n/e)^{n/2})$.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the output is too large to be represented.
§Examples
See here.
source§impl DoubleFactorial for usize
impl DoubleFactorial for usize
source§fn double_factorial(n: u64) -> usize
fn double_factorial(n: u64) -> usize
Computes the double factorial of a number.
If the input is too large, the function panics. For a function that returns None
instead, try
checked_double_factorial
.
$$ f(n) = n!! = n \times (n - 2) \times (n - 4) \times \cdots \times i, $$ where $i$ is 1 if $n$ is odd and $2$ if $n$ is even.
$n!! = O(\sqrt{n}(n/e)^{n/2})$.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the output is too large to be represented.
§Examples
See here.