Expand description
The Iverson bracket: converts a bool
to 0
or 1.
Required Methods
Implementors
impl<T: One + Sized + Zero> Iverson for T
Converts a bool
to 0 or 1.
This function is known as the Iverson bracket.
$$ f(P) = [P] = \begin{cases} 1 & \text{if} \quad P, \\ 0 & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
use malachite_base::num::basic::traits::Iverson;
assert_eq!(u32::iverson(false), 0);
assert_eq!(i8::iverson(true), 1);