Trait SaturatingSquare

Source
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.

Source§

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.

Source§

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.

Source§

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.

Source§

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.

Source§

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.

Source§

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.

Source§

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.

Source§

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.

Source§

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.

Source§

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.

Source§

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.

Source§

type Output = usize

Implementors§