pub trait ArithmeticCheckedShr<RHS> {
    type Output;

    // Required method
    fn arithmetic_checked_shr(self, other: RHS) -> Option<Self::Output>;
}
Expand description

Right-shifts a number (divides it by a power of 2), returning None if the result is not representable.

Required Associated Types§

Required Methods§

source

fn arithmetic_checked_shr(self, other: RHS) -> Option<Self::Output>

Implementations on Foreign Types§

source§

impl ArithmeticCheckedShr<i8> for i8

source§

fn arithmetic_checked_shr(self, bits: i8) -> Option<i8>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i8

source§

impl ArithmeticCheckedShr<i8> for i16

source§

fn arithmetic_checked_shr(self, bits: i8) -> Option<i16>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i16

source§

impl ArithmeticCheckedShr<i8> for i32

source§

fn arithmetic_checked_shr(self, bits: i8) -> Option<i32>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i32

source§

impl ArithmeticCheckedShr<i8> for i64

source§

fn arithmetic_checked_shr(self, bits: i8) -> Option<i64>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i64

source§

impl ArithmeticCheckedShr<i8> for i128

source§

fn arithmetic_checked_shr(self, bits: i8) -> Option<i128>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i128

source§

impl ArithmeticCheckedShr<i8> for isize

source§

fn arithmetic_checked_shr(self, bits: i8) -> Option<isize>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = isize

source§

impl ArithmeticCheckedShr<i8> for u8

source§

fn arithmetic_checked_shr(self, bits: i8) -> Option<u8>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<i8> for u16

source§

fn arithmetic_checked_shr(self, bits: i8) -> Option<u16>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<i8> for u32

source§

fn arithmetic_checked_shr(self, bits: i8) -> Option<u32>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<i8> for u64

source§

fn arithmetic_checked_shr(self, bits: i8) -> Option<u64>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<i8> for u128

source§

fn arithmetic_checked_shr(self, bits: i8) -> Option<u128>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<i8> for usize

source§

fn arithmetic_checked_shr(self, bits: i8) -> Option<usize>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \geq 2^W, \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = usize

source§

impl ArithmeticCheckedShr<i16> for i8

source§

fn arithmetic_checked_shr(self, bits: i16) -> Option<i8>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i8

source§

impl ArithmeticCheckedShr<i16> for i16

source§

fn arithmetic_checked_shr(self, bits: i16) -> Option<i16>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i16

source§

impl ArithmeticCheckedShr<i16> for i32

source§

fn arithmetic_checked_shr(self, bits: i16) -> Option<i32>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i32

source§

impl ArithmeticCheckedShr<i16> for i64

source§

fn arithmetic_checked_shr(self, bits: i16) -> Option<i64>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i64

source§

impl ArithmeticCheckedShr<i16> for i128

source§

fn arithmetic_checked_shr(self, bits: i16) -> Option<i128>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i128

source§

impl ArithmeticCheckedShr<i16> for isize

source§

fn arithmetic_checked_shr(self, bits: i16) -> Option<isize>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = isize

source§

impl ArithmeticCheckedShr<i16> for u8

source§

fn arithmetic_checked_shr(self, bits: i16) -> Option<u8>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<i16> for u16

source§

fn arithmetic_checked_shr(self, bits: i16) -> Option<u16>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<i16> for u32

source§

fn arithmetic_checked_shr(self, bits: i16) -> Option<u32>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<i16> for u64

source§

fn arithmetic_checked_shr(self, bits: i16) -> Option<u64>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<i16> for u128

source§

fn arithmetic_checked_shr(self, bits: i16) -> Option<u128>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<i16> for usize

source§

fn arithmetic_checked_shr(self, bits: i16) -> Option<usize>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \geq 2^W, \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = usize

source§

impl ArithmeticCheckedShr<i32> for i8

source§

fn arithmetic_checked_shr(self, bits: i32) -> Option<i8>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i8

source§

impl ArithmeticCheckedShr<i32> for i16

source§

fn arithmetic_checked_shr(self, bits: i32) -> Option<i16>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i16

source§

impl ArithmeticCheckedShr<i32> for i32

source§

fn arithmetic_checked_shr(self, bits: i32) -> Option<i32>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i32

source§

impl ArithmeticCheckedShr<i32> for i64

source§

fn arithmetic_checked_shr(self, bits: i32) -> Option<i64>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i64

source§

impl ArithmeticCheckedShr<i32> for i128

source§

fn arithmetic_checked_shr(self, bits: i32) -> Option<i128>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i128

source§

impl ArithmeticCheckedShr<i32> for isize

source§

fn arithmetic_checked_shr(self, bits: i32) -> Option<isize>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = isize

source§

impl ArithmeticCheckedShr<i32> for u8

source§

fn arithmetic_checked_shr(self, bits: i32) -> Option<u8>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<i32> for u16

source§

fn arithmetic_checked_shr(self, bits: i32) -> Option<u16>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<i32> for u32

source§

fn arithmetic_checked_shr(self, bits: i32) -> Option<u32>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<i32> for u64

source§

fn arithmetic_checked_shr(self, bits: i32) -> Option<u64>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<i32> for u128

source§

fn arithmetic_checked_shr(self, bits: i32) -> Option<u128>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<i32> for usize

source§

fn arithmetic_checked_shr(self, bits: i32) -> Option<usize>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \geq 2^W, \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = usize

source§

impl ArithmeticCheckedShr<i64> for i8

source§

fn arithmetic_checked_shr(self, bits: i64) -> Option<i8>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i8

source§

impl ArithmeticCheckedShr<i64> for i16

source§

fn arithmetic_checked_shr(self, bits: i64) -> Option<i16>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i16

source§

impl ArithmeticCheckedShr<i64> for i32

source§

fn arithmetic_checked_shr(self, bits: i64) -> Option<i32>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i32

source§

impl ArithmeticCheckedShr<i64> for i64

source§

fn arithmetic_checked_shr(self, bits: i64) -> Option<i64>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i64

source§

impl ArithmeticCheckedShr<i64> for i128

source§

fn arithmetic_checked_shr(self, bits: i64) -> Option<i128>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i128

source§

impl ArithmeticCheckedShr<i64> for isize

source§

fn arithmetic_checked_shr(self, bits: i64) -> Option<isize>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = isize

source§

impl ArithmeticCheckedShr<i64> for u8

source§

fn arithmetic_checked_shr(self, bits: i64) -> Option<u8>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<i64> for u16

source§

fn arithmetic_checked_shr(self, bits: i64) -> Option<u16>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<i64> for u32

source§

fn arithmetic_checked_shr(self, bits: i64) -> Option<u32>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<i64> for u64

source§

fn arithmetic_checked_shr(self, bits: i64) -> Option<u64>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<i64> for u128

source§

fn arithmetic_checked_shr(self, bits: i64) -> Option<u128>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<i64> for usize

source§

fn arithmetic_checked_shr(self, bits: i64) -> Option<usize>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \geq 2^W, \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = usize

source§

impl ArithmeticCheckedShr<i128> for i8

source§

fn arithmetic_checked_shr(self, bits: i128) -> Option<i8>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i8

source§

impl ArithmeticCheckedShr<i128> for i16

source§

fn arithmetic_checked_shr(self, bits: i128) -> Option<i16>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i16

source§

impl ArithmeticCheckedShr<i128> for i32

source§

fn arithmetic_checked_shr(self, bits: i128) -> Option<i32>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i32

source§

impl ArithmeticCheckedShr<i128> for i64

source§

fn arithmetic_checked_shr(self, bits: i128) -> Option<i64>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i64

source§

impl ArithmeticCheckedShr<i128> for i128

source§

fn arithmetic_checked_shr(self, bits: i128) -> Option<i128>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i128

source§

impl ArithmeticCheckedShr<i128> for isize

source§

fn arithmetic_checked_shr(self, bits: i128) -> Option<isize>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = isize

source§

impl ArithmeticCheckedShr<i128> for u8

source§

fn arithmetic_checked_shr(self, bits: i128) -> Option<u8>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<i128> for u16

source§

fn arithmetic_checked_shr(self, bits: i128) -> Option<u16>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<i128> for u32

source§

fn arithmetic_checked_shr(self, bits: i128) -> Option<u32>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<i128> for u64

source§

fn arithmetic_checked_shr(self, bits: i128) -> Option<u64>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<i128> for u128

source§

fn arithmetic_checked_shr(self, bits: i128) -> Option<u128>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<i128> for usize

source§

fn arithmetic_checked_shr(self, bits: i128) -> Option<usize>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \geq 2^W, \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = usize

source§

impl ArithmeticCheckedShr<isize> for i8

source§

fn arithmetic_checked_shr(self, bits: isize) -> Option<i8>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i8

source§

impl ArithmeticCheckedShr<isize> for i16

source§

fn arithmetic_checked_shr(self, bits: isize) -> Option<i16>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i16

source§

impl ArithmeticCheckedShr<isize> for i32

source§

fn arithmetic_checked_shr(self, bits: isize) -> Option<i32>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i32

source§

impl ArithmeticCheckedShr<isize> for i64

source§

fn arithmetic_checked_shr(self, bits: isize) -> Option<i64>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i64

source§

impl ArithmeticCheckedShr<isize> for i128

source§

fn arithmetic_checked_shr(self, bits: isize) -> Option<i128>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = i128

source§

impl ArithmeticCheckedShr<isize> for isize

source§

fn arithmetic_checked_shr(self, bits: isize) -> Option<isize>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0) if self is positive, and Some(-1) if self is negative.

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ -2^{W-1} \leq 2^{-b} x < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ (2^{-b} x < -2^{W-1} \ \mathrm{or} \ 2^{-b} x \geq 2^{W-1}), \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = isize

source§

impl ArithmeticCheckedShr<isize> for u8

source§

fn arithmetic_checked_shr(self, bits: isize) -> Option<u8>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<isize> for u16

source§

fn arithmetic_checked_shr(self, bits: isize) -> Option<u16>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<isize> for u32

source§

fn arithmetic_checked_shr(self, bits: isize) -> Option<u32>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<isize> for u64

source§

fn arithmetic_checked_shr(self, bits: isize) -> Option<u64>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<isize> for u128

source§

fn arithmetic_checked_shr(self, bits: isize) -> Option<u128>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \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 ArithmeticCheckedShr<isize> for usize

source§

fn arithmetic_checked_shr(self, bits: isize) -> Option<usize>

Shifts a number right (divides it by a power of 2). If the result is too large to be represented, None is returned.

Zero may be shifted by any amount, and any number may be shifted by any non-negative amount; shifting by a large amount returns Some(0).

$$ f(x, b) = \begin{cases} \operatorname{Some}(\lfloor x/2^b \rfloor) & \text{if} \quad b \geq 0, \\ \operatorname{Some}(2^{-b} x) & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x < 2^W, \\ \operatorname{None} & \text{if} \quad b < 0 \ \mathrm{and} \ 2^{-b} x \geq 2^W, \\ \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Output = usize

Implementors§