Trait 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§

Implementations on Foreign Types§

Source§

impl CheckedSquare for i8

Source§

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.

Source§

type Output = i8

Source§

impl CheckedSquare for i16

Source§

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.

Source§

type Output = i16

Source§

impl CheckedSquare for i32

Source§

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.

Source§

type Output = i32

Source§

impl CheckedSquare for i64

Source§

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.

Source§

type Output = i64

Source§

impl CheckedSquare for i128

Source§

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.

Source§

type Output = i128

Source§

impl CheckedSquare for isize

Source§

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.

Source§

type Output = isize

Source§

impl CheckedSquare for u8

Source§

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.

Source§

type Output = u8

Source§

impl CheckedSquare for u16

Source§

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.

Source§

type Output = u16

Source§

impl CheckedSquare for u32

Source§

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.

Source§

type Output = u32

Source§

impl CheckedSquare for u64

Source§

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.

Source§

type Output = u64

Source§

impl CheckedSquare for u128

Source§

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.

Source§

type Output = u128

Source§

impl CheckedSquare for usize

Source§

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.

Source§

type Output = usize

Implementors§