pub trait SaturatingSquare {
    type Output;

    // Required method
    fn saturating_square(self) -> Self::Output;
}
Expand description

Squares a number, saturating at the numeric bounds instead of overflowing.

Required Associated Types§

Required Methods§

Implementations on Foreign Types§

source§

impl SaturatingSquare for i8

source§

fn saturating_square(self) -> i8

Squares a number, saturating at the numeric bounds instead of overflowing.

$$ f(x) = \begin{cases} x^2 & \text{if} \quad x^2 \leq M, \\ M & \text{if} \quad x^2 > M, \end{cases} $$ where $M$ is Self::MAX.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i8

source§

impl SaturatingSquare for i16

source§

fn saturating_square(self) -> i16

Squares a number, saturating at the numeric bounds instead of overflowing.

$$ f(x) = \begin{cases} x^2 & \text{if} \quad x^2 \leq M, \\ M & \text{if} \quad x^2 > M, \end{cases} $$ where $M$ is Self::MAX.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i16

source§

impl SaturatingSquare for i32

source§

fn saturating_square(self) -> i32

Squares a number, saturating at the numeric bounds instead of overflowing.

$$ f(x) = \begin{cases} x^2 & \text{if} \quad x^2 \leq M, \\ M & \text{if} \quad x^2 > M, \end{cases} $$ where $M$ is Self::MAX.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i32

source§

impl SaturatingSquare for i64

source§

fn saturating_square(self) -> i64

Squares a number, saturating at the numeric bounds instead of overflowing.

$$ f(x) = \begin{cases} x^2 & \text{if} \quad x^2 \leq M, \\ M & \text{if} \quad x^2 > M, \end{cases} $$ where $M$ is Self::MAX.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i64

source§

impl SaturatingSquare for i128

source§

fn saturating_square(self) -> i128

Squares a number, saturating at the numeric bounds instead of overflowing.

$$ f(x) = \begin{cases} x^2 & \text{if} \quad x^2 \leq M, \\ M & \text{if} \quad x^2 > M, \end{cases} $$ where $M$ is Self::MAX.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i128

source§

impl SaturatingSquare for isize

source§

fn saturating_square(self) -> isize

Squares a number, saturating at the numeric bounds instead of overflowing.

$$ f(x) = \begin{cases} x^2 & \text{if} \quad x^2 \leq M, \\ M & \text{if} \quad x^2 > M, \end{cases} $$ where $M$ is Self::MAX.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = isize

source§

impl SaturatingSquare for u8

source§

fn saturating_square(self) -> u8

Squares a number, saturating at the numeric bounds instead of overflowing.

$$ f(x) = \begin{cases} x^2 & \text{if} \quad x^2 \leq M, \\ M & \text{if} \quad x^2 > M, \end{cases} $$ where $M$ is Self::MAX.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = u8

source§

impl SaturatingSquare for u16

source§

fn saturating_square(self) -> u16

Squares a number, saturating at the numeric bounds instead of overflowing.

$$ f(x) = \begin{cases} x^2 & \text{if} \quad x^2 \leq M, \\ M & \text{if} \quad x^2 > M, \end{cases} $$ where $M$ is Self::MAX.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = u16

source§

impl SaturatingSquare for u32

source§

fn saturating_square(self) -> u32

Squares a number, saturating at the numeric bounds instead of overflowing.

$$ f(x) = \begin{cases} x^2 & \text{if} \quad x^2 \leq M, \\ M & \text{if} \quad x^2 > M, \end{cases} $$ where $M$ is Self::MAX.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = u32

source§

impl SaturatingSquare for u64

source§

fn saturating_square(self) -> u64

Squares a number, saturating at the numeric bounds instead of overflowing.

$$ f(x) = \begin{cases} x^2 & \text{if} \quad x^2 \leq M, \\ M & \text{if} \quad x^2 > M, \end{cases} $$ where $M$ is Self::MAX.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = u64

source§

impl SaturatingSquare for u128

source§

fn saturating_square(self) -> u128

Squares a number, saturating at the numeric bounds instead of overflowing.

$$ f(x) = \begin{cases} x^2 & \text{if} \quad x^2 \leq M, \\ M & \text{if} \quad x^2 > M, \end{cases} $$ where $M$ is Self::MAX.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = u128

source§

impl SaturatingSquare for usize

source§

fn saturating_square(self) -> usize

Squares a number, saturating at the numeric bounds instead of overflowing.

$$ f(x) = \begin{cases} x^2 & \text{if} \quad x^2 \leq M, \\ M & \text{if} \quad x^2 > M, \end{cases} $$ where $M$ is Self::MAX.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = usize

Implementors§