Trait gstreamer::prelude::MulDiv[][src]

pub trait MulDiv<RHS = Self> {
    type Output;
    fn mul_div_floor(self, num: RHS, denom: RHS) -> Option<Self::Output>;
fn mul_div_round(self, num: RHS, denom: RHS) -> Option<Self::Output>;
fn mul_div_ceil(self, num: RHS, denom: RHS) -> Option<Self::Output>; }

Trait for calculating val * num / denom with different rounding modes and overflow protection.

Implementations of this trait have to ensure that even if the result of the multiplication does not fit into the type, as long as it would fit after the division the correct result has to be returned instead of None. None only should be returned if the overall result does not fit into the type.

This specifically means that e.g. the u64 implementation must, depending on the arguments, be able to do 128 bit integer multiplication.

Associated Types

type Output[src]

Output type for the methods of this trait.

Loading content...

Required methods

fn mul_div_floor(self, num: RHS, denom: RHS) -> Option<Self::Output>[src]

Calculates floor(val * num / denom), i.e. the largest integer less than or equal to the result of the division.

Example

extern crate muldiv;
use muldiv::MulDiv;

let x = 3i8.mul_div_floor(4, 2);
assert_eq!(x, Some(6));

let x = 5i8.mul_div_floor(2, 3);
assert_eq!(x, Some(3));

let x = (-5i8).mul_div_floor(2, 3);
assert_eq!(x, Some(-4));

let x = 3i8.mul_div_floor(3, 2);
assert_eq!(x, Some(4));

let x = (-3i8).mul_div_floor(3, 2);
assert_eq!(x, Some(-5));

let x = 127i8.mul_div_floor(4, 3);
assert_eq!(x, None);

fn mul_div_round(self, num: RHS, denom: RHS) -> Option<Self::Output>[src]

Calculates round(val * num / denom), i.e. the closest integer to the result of the division. If both surrounding integers are the same distance (x.5), the one with the bigger absolute value is returned (round away from 0.0).

Example

extern crate muldiv;
use muldiv::MulDiv;

let x = 3i8.mul_div_round(4, 2);
assert_eq!(x, Some(6));

let x = 5i8.mul_div_round(2, 3);
assert_eq!(x, Some(3));

let x = (-5i8).mul_div_round(2, 3);
assert_eq!(x, Some(-3));

let x = 3i8.mul_div_round(3, 2);
assert_eq!(x, Some(5));

let x = (-3i8).mul_div_round(3, 2);
assert_eq!(x, Some(-5));

let x = 127i8.mul_div_round(4, 3);
assert_eq!(x, None);

fn mul_div_ceil(self, num: RHS, denom: RHS) -> Option<Self::Output>[src]

Calculates ceil(val * num / denom), i.e. the the smallest integer greater than or equal to the result of the division.

Example

extern crate muldiv;
use muldiv::MulDiv;

let x = 3i8.mul_div_ceil(4, 2);
assert_eq!(x, Some(6));

let x = 5i8.mul_div_ceil(2, 3);
assert_eq!(x, Some(4));

let x = (-5i8).mul_div_ceil(2, 3);
assert_eq!(x, Some(-3));

let x = 3i8.mul_div_ceil(3, 2);
assert_eq!(x, Some(5));

let x = (-3i8).mul_div_ceil(3, 2);
assert_eq!(x, Some(-4));

let x = (127i8).mul_div_ceil(4, 3);
assert_eq!(x, None);
Loading content...

Implementations on Foreign Types

impl MulDiv<i8> for i8[src]

type Output = i8

pub fn mul_div_floor(self, num: i8, denom: i8) -> Option<i8>[src]

pub fn mul_div_round(self, num: i8, denom: i8) -> Option<i8>[src]

pub fn mul_div_ceil(self, num: i8, denom: i8) -> Option<i8>[src]

impl MulDiv<u8> for u8[src]

type Output = u8

pub fn mul_div_floor(self, num: u8, denom: u8) -> Option<u8>[src]

pub fn mul_div_round(self, num: u8, denom: u8) -> Option<u8>[src]

pub fn mul_div_ceil(self, num: u8, denom: u8) -> Option<u8>[src]

impl MulDiv<u16> for u16[src]

type Output = u16

pub fn mul_div_floor(self, num: u16, denom: u16) -> Option<u16>[src]

pub fn mul_div_round(self, num: u16, denom: u16) -> Option<u16>[src]

pub fn mul_div_ceil(self, num: u16, denom: u16) -> Option<u16>[src]

impl MulDiv<i16> for i16[src]

type Output = i16

pub fn mul_div_floor(self, num: i16, denom: i16) -> Option<i16>[src]

pub fn mul_div_round(self, num: i16, denom: i16) -> Option<i16>[src]

pub fn mul_div_ceil(self, num: i16, denom: i16) -> Option<i16>[src]

impl MulDiv<i32> for i32[src]

type Output = i32

pub fn mul_div_floor(self, num: i32, denom: i32) -> Option<i32>[src]

pub fn mul_div_round(self, num: i32, denom: i32) -> Option<i32>[src]

pub fn mul_div_ceil(self, num: i32, denom: i32) -> Option<i32>[src]

impl MulDiv<i64> for i64[src]

type Output = i64

pub fn mul_div_floor(self, num: i64, denom: i64) -> Option<i64>[src]

pub fn mul_div_round(self, num: i64, denom: i64) -> Option<i64>[src]

pub fn mul_div_ceil(self, num: i64, denom: i64) -> Option<i64>[src]

impl MulDiv<u32> for u32[src]

type Output = u32

pub fn mul_div_floor(self, num: u32, denom: u32) -> Option<u32>[src]

pub fn mul_div_round(self, num: u32, denom: u32) -> Option<u32>[src]

pub fn mul_div_ceil(self, num: u32, denom: u32) -> Option<u32>[src]

impl MulDiv<u64> for u64[src]

type Output = u64

pub fn mul_div_floor(self, num: u64, denom: u64) -> Option<u64>[src]

pub fn mul_div_round(self, num: u64, denom: u64) -> Option<u64>[src]

pub fn mul_div_ceil(self, num: u64, denom: u64) -> Option<u64>[src]

Loading content...

Implementors

impl MulDiv<Buffers> for Buffers[src]

type Output = Buffers

fn mul_div_floor(self, num: Buffers, denom: Buffers) -> Option<Self::Output>[src]

fn mul_div_round(self, num: Buffers, denom: Buffers) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: Buffers, denom: Buffers) -> Option<Self::Output>[src]

impl MulDiv<Bytes> for Bytes[src]

type Output = Bytes

fn mul_div_floor(self, num: Bytes, denom: Bytes) -> Option<Self::Output>[src]

fn mul_div_round(self, num: Bytes, denom: Bytes) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: Bytes, denom: Bytes) -> Option<Self::Output>[src]

impl MulDiv<Default> for Default[src]

type Output = Default

fn mul_div_floor(self, num: Default, denom: Default) -> Option<Self::Output>[src]

fn mul_div_round(self, num: Default, denom: Default) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: Default, denom: Default) -> Option<Self::Output>[src]

impl MulDiv<ClockTime> for ClockTime[src]

type Output = ClockTime

fn mul_div_floor(self, num: ClockTime, denom: ClockTime) -> Option<Self::Output>[src]

fn mul_div_round(self, num: ClockTime, denom: ClockTime) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: ClockTime, denom: ClockTime) -> Option<Self::Output>[src]

impl<'a> MulDiv<&'a u64> for Buffers[src]

type Output = Buffers

fn mul_div_floor(self, num: &u64, denom: &u64) -> Option<Self::Output>[src]

fn mul_div_round(self, num: &u64, denom: &u64) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: &u64, denom: &u64) -> Option<Self::Output>[src]

impl<'a> MulDiv<&'a u64> for Bytes[src]

type Output = Bytes

fn mul_div_floor(self, num: &u64, denom: &u64) -> Option<Self::Output>[src]

fn mul_div_round(self, num: &u64, denom: &u64) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: &u64, denom: &u64) -> Option<Self::Output>[src]

impl<'a> MulDiv<&'a u64> for Default[src]

type Output = Default

fn mul_div_floor(self, num: &u64, denom: &u64) -> Option<Self::Output>[src]

fn mul_div_round(self, num: &u64, denom: &u64) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: &u64, denom: &u64) -> Option<Self::Output>[src]

impl<'a> MulDiv<&'a u64> for ClockTime[src]

type Output = ClockTime

fn mul_div_floor(self, num: &u64, denom: &u64) -> Option<Self::Output>[src]

fn mul_div_round(self, num: &u64, denom: &u64) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: &u64, denom: &u64) -> Option<Self::Output>[src]

impl<'a> MulDiv<&'a Buffers> for Buffers[src]

type Output = Buffers

fn mul_div_floor(self, num: &Buffers, denom: &Buffers) -> Option<Self::Output>[src]

fn mul_div_round(self, num: &Buffers, denom: &Buffers) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: &Buffers, denom: &Buffers) -> Option<Self::Output>[src]

impl<'a> MulDiv<&'a Bytes> for Bytes[src]

type Output = Bytes

fn mul_div_floor(self, num: &Bytes, denom: &Bytes) -> Option<Self::Output>[src]

fn mul_div_round(self, num: &Bytes, denom: &Bytes) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: &Bytes, denom: &Bytes) -> Option<Self::Output>[src]

impl<'a> MulDiv<&'a Default> for Default[src]

type Output = Default

fn mul_div_floor(self, num: &Default, denom: &Default) -> Option<Self::Output>[src]

fn mul_div_round(self, num: &Default, denom: &Default) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: &Default, denom: &Default) -> Option<Self::Output>[src]

impl<'a> MulDiv<&'a ClockTime> for ClockTime[src]

type Output = ClockTime

fn mul_div_floor(
    self,
    num: &ClockTime,
    denom: &ClockTime
) -> Option<Self::Output>
[src]

fn mul_div_round(
    self,
    num: &ClockTime,
    denom: &ClockTime
) -> Option<Self::Output>
[src]

fn mul_div_ceil(
    self,
    num: &ClockTime,
    denom: &ClockTime
) -> Option<Self::Output>
[src]

impl<'a> MulDiv<u64> for &'a Buffers[src]

type Output = Buffers

fn mul_div_floor(self, num: u64, denom: u64) -> Option<Self::Output>[src]

fn mul_div_round(self, num: u64, denom: u64) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: u64, denom: u64) -> Option<Self::Output>[src]

impl<'a> MulDiv<u64> for &'a Bytes[src]

type Output = Bytes

fn mul_div_floor(self, num: u64, denom: u64) -> Option<Self::Output>[src]

fn mul_div_round(self, num: u64, denom: u64) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: u64, denom: u64) -> Option<Self::Output>[src]

impl<'a> MulDiv<u64> for &'a Default[src]

type Output = Default

fn mul_div_floor(self, num: u64, denom: u64) -> Option<Self::Output>[src]

fn mul_div_round(self, num: u64, denom: u64) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: u64, denom: u64) -> Option<Self::Output>[src]

impl<'a> MulDiv<u64> for &'a ClockTime[src]

type Output = ClockTime

fn mul_div_floor(self, num: u64, denom: u64) -> Option<Self::Output>[src]

fn mul_div_round(self, num: u64, denom: u64) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: u64, denom: u64) -> Option<Self::Output>[src]

impl<'a> MulDiv<u64> for Buffers[src]

type Output = Buffers

fn mul_div_floor(self, num: u64, denom: u64) -> Option<Self::Output>[src]

fn mul_div_round(self, num: u64, denom: u64) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: u64, denom: u64) -> Option<Self::Output>[src]

impl<'a> MulDiv<u64> for Bytes[src]

type Output = Bytes

fn mul_div_floor(self, num: u64, denom: u64) -> Option<Self::Output>[src]

fn mul_div_round(self, num: u64, denom: u64) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: u64, denom: u64) -> Option<Self::Output>[src]

impl<'a> MulDiv<u64> for Default[src]

type Output = Default

fn mul_div_floor(self, num: u64, denom: u64) -> Option<Self::Output>[src]

fn mul_div_round(self, num: u64, denom: u64) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: u64, denom: u64) -> Option<Self::Output>[src]

impl<'a> MulDiv<u64> for ClockTime[src]

type Output = ClockTime

fn mul_div_floor(self, num: u64, denom: u64) -> Option<Self::Output>[src]

fn mul_div_round(self, num: u64, denom: u64) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: u64, denom: u64) -> Option<Self::Output>[src]

impl<'a> MulDiv<Buffers> for &'a Buffers[src]

type Output = Buffers

fn mul_div_floor(self, num: Buffers, denom: Buffers) -> Option<Self::Output>[src]

fn mul_div_round(self, num: Buffers, denom: Buffers) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: Buffers, denom: Buffers) -> Option<Self::Output>[src]

impl<'a> MulDiv<Bytes> for &'a Bytes[src]

type Output = Bytes

fn mul_div_floor(self, num: Bytes, denom: Bytes) -> Option<Self::Output>[src]

fn mul_div_round(self, num: Bytes, denom: Bytes) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: Bytes, denom: Bytes) -> Option<Self::Output>[src]

impl<'a> MulDiv<Default> for &'a Default[src]

type Output = Default

fn mul_div_floor(self, num: Default, denom: Default) -> Option<Self::Output>[src]

fn mul_div_round(self, num: Default, denom: Default) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: Default, denom: Default) -> Option<Self::Output>[src]

impl<'a> MulDiv<ClockTime> for &'a ClockTime[src]

type Output = ClockTime

fn mul_div_floor(self, num: ClockTime, denom: ClockTime) -> Option<Self::Output>[src]

fn mul_div_round(self, num: ClockTime, denom: ClockTime) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: ClockTime, denom: ClockTime) -> Option<Self::Output>[src]

impl<'a, 'b> MulDiv<&'a u64> for &'b Buffers[src]

type Output = Buffers

fn mul_div_floor(self, num: &u64, denom: &u64) -> Option<Self::Output>[src]

fn mul_div_round(self, num: &u64, denom: &u64) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: &u64, denom: &u64) -> Option<Self::Output>[src]

impl<'a, 'b> MulDiv<&'a u64> for &'b Bytes[src]

type Output = Bytes

fn mul_div_floor(self, num: &u64, denom: &u64) -> Option<Self::Output>[src]

fn mul_div_round(self, num: &u64, denom: &u64) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: &u64, denom: &u64) -> Option<Self::Output>[src]

impl<'a, 'b> MulDiv<&'a u64> for &'b Default[src]

type Output = Default

fn mul_div_floor(self, num: &u64, denom: &u64) -> Option<Self::Output>[src]

fn mul_div_round(self, num: &u64, denom: &u64) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: &u64, denom: &u64) -> Option<Self::Output>[src]

impl<'a, 'b> MulDiv<&'a u64> for &'b ClockTime[src]

type Output = ClockTime

fn mul_div_floor(self, num: &u64, denom: &u64) -> Option<Self::Output>[src]

fn mul_div_round(self, num: &u64, denom: &u64) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: &u64, denom: &u64) -> Option<Self::Output>[src]

impl<'a, 'b> MulDiv<&'b Buffers> for &'a Buffers[src]

type Output = Buffers

fn mul_div_floor(self, num: &Buffers, denom: &Buffers) -> Option<Self::Output>[src]

fn mul_div_round(self, num: &Buffers, denom: &Buffers) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: &Buffers, denom: &Buffers) -> Option<Self::Output>[src]

impl<'a, 'b> MulDiv<&'b Bytes> for &'a Bytes[src]

type Output = Bytes

fn mul_div_floor(self, num: &Bytes, denom: &Bytes) -> Option<Self::Output>[src]

fn mul_div_round(self, num: &Bytes, denom: &Bytes) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: &Bytes, denom: &Bytes) -> Option<Self::Output>[src]

impl<'a, 'b> MulDiv<&'b Default> for &'a Default[src]

type Output = Default

fn mul_div_floor(self, num: &Default, denom: &Default) -> Option<Self::Output>[src]

fn mul_div_round(self, num: &Default, denom: &Default) -> Option<Self::Output>[src]

fn mul_div_ceil(self, num: &Default, denom: &Default) -> Option<Self::Output>[src]

impl<'a, 'b> MulDiv<&'b ClockTime> for &'a ClockTime[src]

type Output = ClockTime

fn mul_div_floor(
    self,
    num: &ClockTime,
    denom: &ClockTime
) -> Option<Self::Output>
[src]

fn mul_div_round(
    self,
    num: &ClockTime,
    denom: &ClockTime
) -> Option<Self::Output>
[src]

fn mul_div_ceil(
    self,
    num: &ClockTime,
    denom: &ClockTime
) -> Option<Self::Output>
[src]

Loading content...