Trait malachite_base::num::arithmetic::traits::CheckedSquare
source · 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>
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.