pub trait CheckedSquare {
type Output;
// Required method
fn checked_square(self) -> Option<Self::Output>;
}Expand description
Squares a number, returning None if the result is not representable.
Required Associated Types§
Required Methods§
fn checked_square(self) -> Option<Self::Output>
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl CheckedSquare for i8
impl CheckedSquare for i8
Source§fn checked_square(self) -> Option<i8>
fn checked_square(self) -> Option<i8>
Squares a number, returning None if the result cannot be represented.
$$
f(x) = \begin{cases}
\operatorname{Some}(x^2) & \text{if} \quad x^2 < 2^W, \\
\operatorname{None} & \text{if} \quad x^2 \geq 2^W,
\end{cases}
$$
where $W$ is Self::WIDTH.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
type Output = i8
Source§impl CheckedSquare for i16
impl CheckedSquare for i16
Source§fn checked_square(self) -> Option<i16>
fn checked_square(self) -> Option<i16>
Squares a number, returning None if the result cannot be represented.
$$
f(x) = \begin{cases}
\operatorname{Some}(x^2) & \text{if} \quad x^2 < 2^W, \\
\operatorname{None} & \text{if} \quad x^2 \geq 2^W,
\end{cases}
$$
where $W$ is Self::WIDTH.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
type Output = i16
Source§impl CheckedSquare for i32
impl CheckedSquare for i32
Source§fn checked_square(self) -> Option<i32>
fn checked_square(self) -> Option<i32>
Squares a number, returning None if the result cannot be represented.
$$
f(x) = \begin{cases}
\operatorname{Some}(x^2) & \text{if} \quad x^2 < 2^W, \\
\operatorname{None} & \text{if} \quad x^2 \geq 2^W,
\end{cases}
$$
where $W$ is Self::WIDTH.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
type Output = i32
Source§impl CheckedSquare for i64
impl CheckedSquare for i64
Source§fn checked_square(self) -> Option<i64>
fn checked_square(self) -> Option<i64>
Squares a number, returning None if the result cannot be represented.
$$
f(x) = \begin{cases}
\operatorname{Some}(x^2) & \text{if} \quad x^2 < 2^W, \\
\operatorname{None} & \text{if} \quad x^2 \geq 2^W,
\end{cases}
$$
where $W$ is Self::WIDTH.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
type Output = i64
Source§impl CheckedSquare for i128
impl CheckedSquare for i128
Source§fn checked_square(self) -> Option<i128>
fn checked_square(self) -> Option<i128>
Squares a number, returning None if the result cannot be represented.
$$
f(x) = \begin{cases}
\operatorname{Some}(x^2) & \text{if} \quad x^2 < 2^W, \\
\operatorname{None} & \text{if} \quad x^2 \geq 2^W,
\end{cases}
$$
where $W$ is Self::WIDTH.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
type Output = i128
Source§impl CheckedSquare for isize
impl CheckedSquare for isize
Source§fn checked_square(self) -> Option<isize>
fn checked_square(self) -> Option<isize>
Squares a number, returning None if the result cannot be represented.
$$
f(x) = \begin{cases}
\operatorname{Some}(x^2) & \text{if} \quad x^2 < 2^W, \\
\operatorname{None} & \text{if} \quad x^2 \geq 2^W,
\end{cases}
$$
where $W$ is Self::WIDTH.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
type Output = isize
Source§impl CheckedSquare for u8
impl CheckedSquare for u8
Source§fn checked_square(self) -> Option<u8>
fn checked_square(self) -> Option<u8>
Squares a number, returning None if the result cannot be represented.
$$
f(x) = \begin{cases}
\operatorname{Some}(x^2) & \text{if} \quad x^2 < 2^W, \\
\operatorname{None} & \text{if} \quad x^2 \geq 2^W,
\end{cases}
$$
where $W$ is Self::WIDTH.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
type Output = u8
Source§impl CheckedSquare for u16
impl CheckedSquare for u16
Source§fn checked_square(self) -> Option<u16>
fn checked_square(self) -> Option<u16>
Squares a number, returning None if the result cannot be represented.
$$
f(x) = \begin{cases}
\operatorname{Some}(x^2) & \text{if} \quad x^2 < 2^W, \\
\operatorname{None} & \text{if} \quad x^2 \geq 2^W,
\end{cases}
$$
where $W$ is Self::WIDTH.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
type Output = u16
Source§impl CheckedSquare for u32
impl CheckedSquare for u32
Source§fn checked_square(self) -> Option<u32>
fn checked_square(self) -> Option<u32>
Squares a number, returning None if the result cannot be represented.
$$
f(x) = \begin{cases}
\operatorname{Some}(x^2) & \text{if} \quad x^2 < 2^W, \\
\operatorname{None} & \text{if} \quad x^2 \geq 2^W,
\end{cases}
$$
where $W$ is Self::WIDTH.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
type Output = u32
Source§impl CheckedSquare for u64
impl CheckedSquare for u64
Source§fn checked_square(self) -> Option<u64>
fn checked_square(self) -> Option<u64>
Squares a number, returning None if the result cannot be represented.
$$
f(x) = \begin{cases}
\operatorname{Some}(x^2) & \text{if} \quad x^2 < 2^W, \\
\operatorname{None} & \text{if} \quad x^2 \geq 2^W,
\end{cases}
$$
where $W$ is Self::WIDTH.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
type Output = u64
Source§impl CheckedSquare for u128
impl CheckedSquare for u128
Source§fn checked_square(self) -> Option<u128>
fn checked_square(self) -> Option<u128>
Squares a number, returning None if the result cannot be represented.
$$
f(x) = \begin{cases}
\operatorname{Some}(x^2) & \text{if} \quad x^2 < 2^W, \\
\operatorname{None} & \text{if} \quad x^2 \geq 2^W,
\end{cases}
$$
where $W$ is Self::WIDTH.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
type Output = u128
Source§impl CheckedSquare for usize
impl CheckedSquare for usize
Source§fn checked_square(self) -> Option<usize>
fn checked_square(self) -> Option<usize>
Squares a number, returning None if the result cannot be represented.
$$
f(x) = \begin{cases}
\operatorname{Some}(x^2) & \text{if} \quad x^2 < 2^W, \\
\operatorname{None} & \text{if} \quad x^2 \geq 2^W,
\end{cases}
$$
where $W$ is Self::WIDTH.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.