pub trait CheckedAddMul<Y = Self, Z = Self> {
    type Output;

    // Required method
    fn checked_add_mul(self, y: Y, z: Z) -> Option<Self::Output>;
}
Expand description

Adds a number and the product of two other numbers, returning None if the result is not representable.

Required Associated Types§

Required Methods§

source

fn checked_add_mul(self, y: Y, z: Z) -> Option<Self::Output>

Implementations on Foreign Types§

source§

impl CheckedAddMul for i8

source§

fn checked_add_mul(self, y: i8, z: i8) -> Option<i8>

Adds a number and the product of two other numbers, returning None if the result cannot be represented.

$$ f(x, y, z) = \begin{cases} \operatorname{Some}(x + yz) & \text{if} \quad -2^{W-1} \leq x + yz < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad x + yz < -2^{W-1} \ \mathrm{or} \ x + yz \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 CheckedAddMul for i16

source§

fn checked_add_mul(self, y: i16, z: i16) -> Option<i16>

Adds a number and the product of two other numbers, returning None if the result cannot be represented.

$$ f(x, y, z) = \begin{cases} \operatorname{Some}(x + yz) & \text{if} \quad -2^{W-1} \leq x + yz < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad x + yz < -2^{W-1} \ \mathrm{or} \ x + yz \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 CheckedAddMul for i32

source§

fn checked_add_mul(self, y: i32, z: i32) -> Option<i32>

Adds a number and the product of two other numbers, returning None if the result cannot be represented.

$$ f(x, y, z) = \begin{cases} \operatorname{Some}(x + yz) & \text{if} \quad -2^{W-1} \leq x + yz < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad x + yz < -2^{W-1} \ \mathrm{or} \ x + yz \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 CheckedAddMul for i64

source§

fn checked_add_mul(self, y: i64, z: i64) -> Option<i64>

Adds a number and the product of two other numbers, returning None if the result cannot be represented.

$$ f(x, y, z) = \begin{cases} \operatorname{Some}(x + yz) & \text{if} \quad -2^{W-1} \leq x + yz < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad x + yz < -2^{W-1} \ \mathrm{or} \ x + yz \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 CheckedAddMul for i128

source§

fn checked_add_mul(self, y: i128, z: i128) -> Option<i128>

Adds a number and the product of two other numbers, returning None if the result cannot be represented.

$$ f(x, y, z) = \begin{cases} \operatorname{Some}(x + yz) & \text{if} \quad -2^{W-1} \leq x + yz < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad x + yz < -2^{W-1} \ \mathrm{or} \ x + yz \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 CheckedAddMul for isize

source§

fn checked_add_mul(self, y: isize, z: isize) -> Option<isize>

Adds a number and the product of two other numbers, returning None if the result cannot be represented.

$$ f(x, y, z) = \begin{cases} \operatorname{Some}(x + yz) & \text{if} \quad -2^{W-1} \leq x + yz < 2^{W-1}, \\ \operatorname{None} & \text{if} \quad x + yz < -2^{W-1} \ \mathrm{or} \ x + yz \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 CheckedAddMul for u8

source§

fn checked_add_mul(self, y: u8, z: u8) -> Option<u8>

Adds a number and the product of two other numbers, returning None if the result cannot be represented.

$$ f(x, y, z) = \begin{cases} \operatorname{Some}(x + yz) & \text{if} \quad x + yz < 2^W, \\ \operatorname{None} & \text{if} \quad x + yz \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 CheckedAddMul for u16

source§

fn checked_add_mul(self, y: u16, z: u16) -> Option<u16>

Adds a number and the product of two other numbers, returning None if the result cannot be represented.

$$ f(x, y, z) = \begin{cases} \operatorname{Some}(x + yz) & \text{if} \quad x + yz < 2^W, \\ \operatorname{None} & \text{if} \quad x + yz \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 CheckedAddMul for u32

source§

fn checked_add_mul(self, y: u32, z: u32) -> Option<u32>

Adds a number and the product of two other numbers, returning None if the result cannot be represented.

$$ f(x, y, z) = \begin{cases} \operatorname{Some}(x + yz) & \text{if} \quad x + yz < 2^W, \\ \operatorname{None} & \text{if} \quad x + yz \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 CheckedAddMul for u64

source§

fn checked_add_mul(self, y: u64, z: u64) -> Option<u64>

Adds a number and the product of two other numbers, returning None if the result cannot be represented.

$$ f(x, y, z) = \begin{cases} \operatorname{Some}(x + yz) & \text{if} \quad x + yz < 2^W, \\ \operatorname{None} & \text{if} \quad x + yz \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 CheckedAddMul for u128

source§

fn checked_add_mul(self, y: u128, z: u128) -> Option<u128>

Adds a number and the product of two other numbers, returning None if the result cannot be represented.

$$ f(x, y, z) = \begin{cases} \operatorname{Some}(x + yz) & \text{if} \quad x + yz < 2^W, \\ \operatorname{None} & \text{if} \quad x + yz \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 CheckedAddMul for usize

source§

fn checked_add_mul(self, y: usize, z: usize) -> Option<usize>

Adds a number and the product of two other numbers, returning None if the result cannot be represented.

$$ f(x, y, z) = \begin{cases} \operatorname{Some}(x + yz) & \text{if} \quad x + yz < 2^W, \\ \operatorname{None} & \text{if} \quad x + yz \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§