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

Implementations on Foreign Types

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

Implementors