Trait gstreamer_base::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
Required Methods
fn mul_div_floor(self, num: RHS, denom: RHS) -> Option<Self::Output>
Calculates floor(val * num / denom)
, i.e. the next integer to the result of the division
with the smaller absolute value.
Example
extern crate muldiv; use muldiv::MulDiv; // Returns x==Some(6) let x = 3i8.mul_div_floor(4, 2); // Returns x==Some(3) let x = 5i8.mul_div_floor(2, 3); // Returns x==Some(-3) let x = (-5i8).mul_div_floor(2, 3); // Returns x==Some(4) let x = 3i8.mul_div_floor(3, 2); // Returns x==Some(-4) let x = (-3i8).mul_div_floor(3, 2); // Returns x==None let x = 127i8.mul_div_floor(4, 3);
fn mul_div_round(self, num: RHS, denom: RHS) -> Option<Self::Output>
Calculates round(val * num / denom)
, i.e. the closest integer to the result of the
division. If both surrounding integers are the same distance, the one with the bigger
absolute value is returned.
Example
extern crate muldiv; use muldiv::MulDiv; // Returns x==Some(6) let x = 3i8.mul_div_round(4, 2); // Returns x==Some(3) let x = 5i8.mul_div_round(2, 3); // Returns x==Some(-3) let x = (-5i8).mul_div_round(2, 3); // Returns x==Some(5) let x = 3i8.mul_div_round(3, 2); // Returns x==Some(-5) let x = (-3i8).mul_div_round(3, 2); // Returns x==None let x = 127i8.mul_div_floor(4, 3);
fn mul_div_ceil(self, num: RHS, denom: RHS) -> Option<Self::Output>
Calculates ceil(val * num / denom)
, i.e. the next integer to the result of the division
with the bigger absolute value.
Example
extern crate muldiv; use muldiv::MulDiv; // Returns x==Some(6) let x = 3i8.mul_div_ceil(4, 2); // Returns x==Some(4) let x = 5i8.mul_div_ceil(2, 3); // Returns x==Some(-4) let x = (-5i8).mul_div_ceil(2, 3); // Returns x==Some(5) let x = 3i8.mul_div_ceil(3, 2); // Returns x==Some(-5) let x = (-3i8).mul_div_ceil(3, 2); // Returns x==None let x = (127i8).mul_div_ceil(4, 3);
Implementations on Foreign Types
impl<'a> MulDiv<u64> for Bytes
[src]
impl<'a> MulDiv<u64> for Bytes
impl<'a> MulDiv<&'a u64> for Buffers
[src]
impl<'a> MulDiv<&'a u64> for Buffers
type Output = Buffers
fn mul_div_floor(
self,
num: &u64,
denom: &u64
) -> Option<<Buffers as MulDiv<&'a u64>>::Output>
[src]
fn mul_div_floor(
self,
num: &u64,
denom: &u64
) -> Option<<Buffers as MulDiv<&'a u64>>::Output>
fn mul_div_round(
self,
num: &u64,
denom: &u64
) -> Option<<Buffers as MulDiv<&'a u64>>::Output>
[src]
fn mul_div_round(
self,
num: &u64,
denom: &u64
) -> Option<<Buffers as MulDiv<&'a u64>>::Output>
fn mul_div_ceil(
self,
num: &u64,
denom: &u64
) -> Option<<Buffers as MulDiv<&'a u64>>::Output>
[src]
fn mul_div_ceil(
self,
num: &u64,
denom: &u64
) -> Option<<Buffers as MulDiv<&'a u64>>::Output>
impl<'a> MulDiv<&'a u64> for Default
[src]
impl<'a> MulDiv<&'a u64> for Default
type Output = Default
fn mul_div_floor(
self,
num: &u64,
denom: &u64
) -> Option<<Default as MulDiv<&'a u64>>::Output>
[src]
fn mul_div_floor(
self,
num: &u64,
denom: &u64
) -> Option<<Default as MulDiv<&'a u64>>::Output>
fn mul_div_round(
self,
num: &u64,
denom: &u64
) -> Option<<Default as MulDiv<&'a u64>>::Output>
[src]
fn mul_div_round(
self,
num: &u64,
denom: &u64
) -> Option<<Default as MulDiv<&'a u64>>::Output>
fn mul_div_ceil(
self,
num: &u64,
denom: &u64
) -> Option<<Default as MulDiv<&'a u64>>::Output>
[src]
fn mul_div_ceil(
self,
num: &u64,
denom: &u64
) -> Option<<Default as MulDiv<&'a u64>>::Output>
impl<'a> MulDiv<u64> for Default
[src]
impl<'a> MulDiv<u64> for Default
type Output = Default
fn mul_div_floor(
self,
num: u64,
denom: u64
) -> Option<<Default as MulDiv<u64>>::Output>
[src]
fn mul_div_floor(
self,
num: u64,
denom: u64
) -> Option<<Default as MulDiv<u64>>::Output>
fn mul_div_round(
self,
num: u64,
denom: u64
) -> Option<<Default as MulDiv<u64>>::Output>
[src]
fn mul_div_round(
self,
num: u64,
denom: u64
) -> Option<<Default as MulDiv<u64>>::Output>
fn mul_div_ceil(
self,
num: u64,
denom: u64
) -> Option<<Default as MulDiv<u64>>::Output>
[src]
fn mul_div_ceil(
self,
num: u64,
denom: u64
) -> Option<<Default as MulDiv<u64>>::Output>
impl MulDiv<Buffers> for Buffers
[src]
impl MulDiv<Buffers> for Buffers
type Output = Buffers
fn mul_div_floor(
self,
num: Buffers,
denom: Buffers
) -> Option<<Buffers as MulDiv<Buffers>>::Output>
[src]
fn mul_div_floor(
self,
num: Buffers,
denom: Buffers
) -> Option<<Buffers as MulDiv<Buffers>>::Output>
fn mul_div_round(
self,
num: Buffers,
denom: Buffers
) -> Option<<Buffers as MulDiv<Buffers>>::Output>
[src]
fn mul_div_round(
self,
num: Buffers,
denom: Buffers
) -> Option<<Buffers as MulDiv<Buffers>>::Output>
fn mul_div_ceil(
self,
num: Buffers,
denom: Buffers
) -> Option<<Buffers as MulDiv<Buffers>>::Output>
[src]
fn mul_div_ceil(
self,
num: Buffers,
denom: Buffers
) -> Option<<Buffers as MulDiv<Buffers>>::Output>
impl<'a> MulDiv<&'a Bytes> for Bytes
[src]
impl<'a> MulDiv<&'a Bytes> for Bytes
type Output = Bytes
fn mul_div_floor(
self,
num: &Bytes,
denom: &Bytes
) -> Option<<Bytes as MulDiv<&'a Bytes>>::Output>
[src]
fn mul_div_floor(
self,
num: &Bytes,
denom: &Bytes
) -> Option<<Bytes as MulDiv<&'a Bytes>>::Output>
fn mul_div_round(
self,
num: &Bytes,
denom: &Bytes
) -> Option<<Bytes as MulDiv<&'a Bytes>>::Output>
[src]
fn mul_div_round(
self,
num: &Bytes,
denom: &Bytes
) -> Option<<Bytes as MulDiv<&'a Bytes>>::Output>
fn mul_div_ceil(
self,
num: &Bytes,
denom: &Bytes
) -> Option<<Bytes as MulDiv<&'a Bytes>>::Output>
[src]
fn mul_div_ceil(
self,
num: &Bytes,
denom: &Bytes
) -> Option<<Bytes as MulDiv<&'a Bytes>>::Output>
impl<'a> MulDiv<&'a u64> for Bytes
[src]
impl<'a> MulDiv<&'a u64> for Bytes
type Output = Bytes
fn mul_div_floor(
self,
num: &u64,
denom: &u64
) -> Option<<Bytes as MulDiv<&'a u64>>::Output>
[src]
fn mul_div_floor(
self,
num: &u64,
denom: &u64
) -> Option<<Bytes as MulDiv<&'a u64>>::Output>
fn mul_div_round(
self,
num: &u64,
denom: &u64
) -> Option<<Bytes as MulDiv<&'a u64>>::Output>
[src]
fn mul_div_round(
self,
num: &u64,
denom: &u64
) -> Option<<Bytes as MulDiv<&'a u64>>::Output>
fn mul_div_ceil(
self,
num: &u64,
denom: &u64
) -> Option<<Bytes as MulDiv<&'a u64>>::Output>
[src]
fn mul_div_ceil(
self,
num: &u64,
denom: &u64
) -> Option<<Bytes as MulDiv<&'a u64>>::Output>
impl<'a> MulDiv<&'a Buffers> for Buffers
[src]
impl<'a> MulDiv<&'a Buffers> for Buffers
type Output = Buffers
fn mul_div_floor(
self,
num: &Buffers,
denom: &Buffers
) -> Option<<Buffers as MulDiv<&'a Buffers>>::Output>
[src]
fn mul_div_floor(
self,
num: &Buffers,
denom: &Buffers
) -> Option<<Buffers as MulDiv<&'a Buffers>>::Output>
fn mul_div_round(
self,
num: &Buffers,
denom: &Buffers
) -> Option<<Buffers as MulDiv<&'a Buffers>>::Output>
[src]
fn mul_div_round(
self,
num: &Buffers,
denom: &Buffers
) -> Option<<Buffers as MulDiv<&'a Buffers>>::Output>
fn mul_div_ceil(
self,
num: &Buffers,
denom: &Buffers
) -> Option<<Buffers as MulDiv<&'a Buffers>>::Output>
[src]
fn mul_div_ceil(
self,
num: &Buffers,
denom: &Buffers
) -> Option<<Buffers as MulDiv<&'a Buffers>>::Output>
impl<'a> MulDiv<&'a u64> for ClockTime
[src]
impl<'a> MulDiv<&'a u64> for ClockTime
type Output = ClockTime
fn mul_div_floor(
self,
num: &u64,
denom: &u64
) -> Option<<ClockTime as MulDiv<&'a u64>>::Output>
[src]
fn mul_div_floor(
self,
num: &u64,
denom: &u64
) -> Option<<ClockTime as MulDiv<&'a u64>>::Output>
fn mul_div_round(
self,
num: &u64,
denom: &u64
) -> Option<<ClockTime as MulDiv<&'a u64>>::Output>
[src]
fn mul_div_round(
self,
num: &u64,
denom: &u64
) -> Option<<ClockTime as MulDiv<&'a u64>>::Output>
fn mul_div_ceil(
self,
num: &u64,
denom: &u64
) -> Option<<ClockTime as MulDiv<&'a u64>>::Output>
[src]
fn mul_div_ceil(
self,
num: &u64,
denom: &u64
) -> Option<<ClockTime as MulDiv<&'a u64>>::Output>
impl MulDiv<Bytes> for Bytes
[src]
impl MulDiv<Bytes> for Bytes
type Output = Bytes
fn mul_div_floor(
self,
num: Bytes,
denom: Bytes
) -> Option<<Bytes as MulDiv<Bytes>>::Output>
[src]
fn mul_div_floor(
self,
num: Bytes,
denom: Bytes
) -> Option<<Bytes as MulDiv<Bytes>>::Output>
fn mul_div_round(
self,
num: Bytes,
denom: Bytes
) -> Option<<Bytes as MulDiv<Bytes>>::Output>
[src]
fn mul_div_round(
self,
num: Bytes,
denom: Bytes
) -> Option<<Bytes as MulDiv<Bytes>>::Output>
fn mul_div_ceil(
self,
num: Bytes,
denom: Bytes
) -> Option<<Bytes as MulDiv<Bytes>>::Output>
[src]
fn mul_div_ceil(
self,
num: Bytes,
denom: Bytes
) -> Option<<Bytes as MulDiv<Bytes>>::Output>
impl MulDiv<ClockTime> for ClockTime
[src]
impl MulDiv<ClockTime> for ClockTime
type Output = ClockTime
fn mul_div_floor(
self,
num: ClockTime,
denom: ClockTime
) -> Option<<ClockTime as MulDiv<ClockTime>>::Output>
[src]
fn mul_div_floor(
self,
num: ClockTime,
denom: ClockTime
) -> Option<<ClockTime as MulDiv<ClockTime>>::Output>
fn mul_div_round(
self,
num: ClockTime,
denom: ClockTime
) -> Option<<ClockTime as MulDiv<ClockTime>>::Output>
[src]
fn mul_div_round(
self,
num: ClockTime,
denom: ClockTime
) -> Option<<ClockTime as MulDiv<ClockTime>>::Output>
fn mul_div_ceil(
self,
num: ClockTime,
denom: ClockTime
) -> Option<<ClockTime as MulDiv<ClockTime>>::Output>
[src]
fn mul_div_ceil(
self,
num: ClockTime,
denom: ClockTime
) -> Option<<ClockTime as MulDiv<ClockTime>>::Output>
impl<'a> MulDiv<u64> for ClockTime
[src]
impl<'a> MulDiv<u64> for ClockTime
type Output = ClockTime
fn mul_div_floor(
self,
num: u64,
denom: u64
) -> Option<<ClockTime as MulDiv<u64>>::Output>
[src]
fn mul_div_floor(
self,
num: u64,
denom: u64
) -> Option<<ClockTime as MulDiv<u64>>::Output>
fn mul_div_round(
self,
num: u64,
denom: u64
) -> Option<<ClockTime as MulDiv<u64>>::Output>
[src]
fn mul_div_round(
self,
num: u64,
denom: u64
) -> Option<<ClockTime as MulDiv<u64>>::Output>
fn mul_div_ceil(
self,
num: u64,
denom: u64
) -> Option<<ClockTime as MulDiv<u64>>::Output>
[src]
fn mul_div_ceil(
self,
num: u64,
denom: u64
) -> Option<<ClockTime as MulDiv<u64>>::Output>
impl<'a> MulDiv<&'a ClockTime> for ClockTime
[src]
impl<'a> MulDiv<&'a ClockTime> for ClockTime
type Output = ClockTime
fn mul_div_floor(
self,
num: &ClockTime,
denom: &ClockTime
) -> Option<<ClockTime as MulDiv<&'a ClockTime>>::Output>
[src]
fn mul_div_floor(
self,
num: &ClockTime,
denom: &ClockTime
) -> Option<<ClockTime as MulDiv<&'a ClockTime>>::Output>
fn mul_div_round(
self,
num: &ClockTime,
denom: &ClockTime
) -> Option<<ClockTime as MulDiv<&'a ClockTime>>::Output>
[src]
fn mul_div_round(
self,
num: &ClockTime,
denom: &ClockTime
) -> Option<<ClockTime as MulDiv<&'a ClockTime>>::Output>
fn mul_div_ceil(
self,
num: &ClockTime,
denom: &ClockTime
) -> Option<<ClockTime as MulDiv<&'a ClockTime>>::Output>
[src]
fn mul_div_ceil(
self,
num: &ClockTime,
denom: &ClockTime
) -> Option<<ClockTime as MulDiv<&'a ClockTime>>::Output>
impl<'a> MulDiv<&'a Default> for Default
[src]
impl<'a> MulDiv<&'a Default> for Default
type Output = Default
fn mul_div_floor(
self,
num: &Default,
denom: &Default
) -> Option<<Default as MulDiv<&'a Default>>::Output>
[src]
fn mul_div_floor(
self,
num: &Default,
denom: &Default
) -> Option<<Default as MulDiv<&'a Default>>::Output>
fn mul_div_round(
self,
num: &Default,
denom: &Default
) -> Option<<Default as MulDiv<&'a Default>>::Output>
[src]
fn mul_div_round(
self,
num: &Default,
denom: &Default
) -> Option<<Default as MulDiv<&'a Default>>::Output>
fn mul_div_ceil(
self,
num: &Default,
denom: &Default
) -> Option<<Default as MulDiv<&'a Default>>::Output>
[src]
fn mul_div_ceil(
self,
num: &Default,
denom: &Default
) -> Option<<Default as MulDiv<&'a Default>>::Output>
impl<'a> MulDiv<u64> for Buffers
[src]
impl<'a> MulDiv<u64> for Buffers
type Output = Buffers
fn mul_div_floor(
self,
num: u64,
denom: u64
) -> Option<<Buffers as MulDiv<u64>>::Output>
[src]
fn mul_div_floor(
self,
num: u64,
denom: u64
) -> Option<<Buffers as MulDiv<u64>>::Output>
fn mul_div_round(
self,
num: u64,
denom: u64
) -> Option<<Buffers as MulDiv<u64>>::Output>
[src]
fn mul_div_round(
self,
num: u64,
denom: u64
) -> Option<<Buffers as MulDiv<u64>>::Output>
fn mul_div_ceil(
self,
num: u64,
denom: u64
) -> Option<<Buffers as MulDiv<u64>>::Output>
[src]
fn mul_div_ceil(
self,
num: u64,
denom: u64
) -> Option<<Buffers as MulDiv<u64>>::Output>
impl MulDiv<Default> for Default
[src]
impl MulDiv<Default> for Default
type Output = Default
fn mul_div_floor(
self,
num: Default,
denom: Default
) -> Option<<Default as MulDiv<Default>>::Output>
[src]
fn mul_div_floor(
self,
num: Default,
denom: Default
) -> Option<<Default as MulDiv<Default>>::Output>
fn mul_div_round(
self,
num: Default,
denom: Default
) -> Option<<Default as MulDiv<Default>>::Output>
[src]
fn mul_div_round(
self,
num: Default,
denom: Default
) -> Option<<Default as MulDiv<Default>>::Output>
fn mul_div_ceil(
self,
num: Default,
denom: Default
) -> Option<<Default as MulDiv<Default>>::Output>
[src]
fn mul_div_ceil(
self,
num: Default,
denom: Default
) -> Option<<Default as MulDiv<Default>>::Output>
impl MulDiv<i64> for i64
[src]
impl MulDiv<i64> for i64
impl MulDiv<u32> for u32
[src]
impl MulDiv<u32> for u32
impl MulDiv<i8> for i8
[src]
impl MulDiv<i8> for i8
impl MulDiv<u64> for u64
[src]
impl MulDiv<u64> for u64
impl MulDiv<u16> for u16
[src]
impl MulDiv<u16> for u16
impl MulDiv<u8> for u8
[src]
impl MulDiv<u8> for u8
impl MulDiv<i16> for i16
[src]
impl MulDiv<i16> for i16
impl MulDiv<i32> for i32
[src]
impl MulDiv<i32> for i32