Trait malachite_base::num::arithmetic::traits::CheckedSquare
source · [−]pub trait CheckedSquare {
type Output;
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>
Implementations on Foreign Types
sourceimpl CheckedSquare for u8
impl CheckedSquare for u8
sourcefn 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
sourceimpl CheckedSquare for u16
impl CheckedSquare for u16
sourcefn 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
sourceimpl CheckedSquare for u32
impl CheckedSquare for u32
sourcefn 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
sourceimpl CheckedSquare for u64
impl CheckedSquare for u64
sourcefn 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
sourceimpl CheckedSquare for u128
impl CheckedSquare for u128
sourcefn 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
sourceimpl CheckedSquare for usize
impl CheckedSquare for usize
sourcefn 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.
type Output = usize
sourceimpl CheckedSquare for i8
impl CheckedSquare for i8
sourcefn 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
sourceimpl CheckedSquare for i16
impl CheckedSquare for i16
sourcefn 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
sourceimpl CheckedSquare for i32
impl CheckedSquare for i32
sourcefn 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
sourceimpl CheckedSquare for i64
impl CheckedSquare for i64
sourcefn 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
sourceimpl CheckedSquare for i128
impl CheckedSquare for i128
sourcefn 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
sourceimpl CheckedSquare for isize
impl CheckedSquare for isize
sourcefn 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.