Skip to main content

Ratio

Struct Ratio 

Source
pub struct Ratio { /* private fields */ }

Implementations§

Source§

impl Ratio

Source

pub const OVERFLOW: i64 = i64::MAX

Source

pub const UNDERFLOW: i64 = i64::MIN

Source

pub fn new(numerator: u32, denominator: u32) -> Self

Source

pub fn numerator(&self) -> u32

Source

pub fn denominator(&self) -> u32

Source

pub fn invertible(&self) -> bool

Source

pub fn inverse(&self) -> Self

Source

pub fn reduce_u32(numerator: &mut u32, denominator: &mut u32)

Reduces the ratio of numerator/denominator in-place (32-bit).

Source

pub fn reduce_u64(numerator: &mut u64, denominator: &mut u64)

Reduces the ratio of numerator/denominator in-place (64-bit).

Source

pub fn reduce(&mut self)

Reduces the ratio instance in-place.

Source

pub fn product_raw( a_numerator: u32, a_denominator: u32, b_numerator: u32, b_denominator: u32, exact: Exact, ) -> (u32, u32)

Produces the product of two ratios.

If exact is Exact::Yes, this panics on loss of precision. If exact is Exact::No, it attempts to find the best 32-bit approximation.

Source

pub fn product(a: Ratio, b: Ratio, exact: Exact) -> Ratio

Source

pub fn scale_with_round<const ROUND: u8>( value: i64, numerator: u32, denominator: u32, ) -> i64

Scales an i64 value by the ratio of numerator/denominator.

Returns a saturated value (OVERFLOW or UNDERFLOW) on overflow/underflow. The rounding behavior is determined by the ROUND const generic.

Source

pub fn scale<const ROUND: u8>(&self, value: i64) -> i64

Scales an i64 value by this ratio.

Returns a saturated value (OVERFLOW or UNDERFLOW) on overflow/underflow. The rounding behavior is determined by the ROUND const generic.

Trait Implementations§

Source§

impl Clone for Ratio

Source§

fn clone(&self) -> Ratio

Returns a duplicate of the value. Read more
1.0.0 (const: unstable)§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Ratio

Source§

impl Debug for Ratio

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Ratio

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Div for Ratio

Source§

type Output = Ratio

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<Ratio> for i64

Source§

type Output = i64

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Ratio) -> Self::Output

Performs the / operation. Read more
Source§

impl Eq for Ratio

Source§

impl FromBytes for Ratio
where u32: FromBytes,

Source§

fn read_from_bytes(source: &[u8]) -> Result<Self, SizeError<&[u8], Self>>
where Self: Sized,

Reads a copy of Self from the given source. Read more
Source§

fn read_from_prefix( source: &[u8], ) -> Result<(Self, &[u8]), SizeError<&[u8], Self>>
where Self: Sized,

Reads a copy of Self from the prefix of the given source. Read more
Source§

fn read_from_suffix( source: &[u8], ) -> Result<(&[u8], Self), SizeError<&[u8], Self>>
where Self: Sized,

Reads a copy of Self from the suffix of the given source. Read more
Source§

impl FromZeros for Ratio
where u32: FromZeros,

Source§

fn zero(&mut self)

Overwrites self with zeros. Read more
Source§

fn new_zeroed() -> Self
where Self: Sized,

Creates an instance of Self from zeroed bytes. Read more
Source§

impl Immutable for Ratio
where u32: Immutable,

Source§

impl IntoBytes for Ratio
where u32: IntoBytes, (): PaddingFree<Self, { _ }>,

Source§

fn as_bytes(&self) -> &[u8]
where Self: Immutable,

Gets the bytes of this value. Read more
Source§

fn as_mut_bytes(&mut self) -> &mut [u8] ⓘ
where Self: FromBytes,

Gets the bytes of this value mutably. Read more
Source§

fn write_to(&self, dst: &mut [u8]) -> Result<(), SizeError<&Self, &mut [u8]>>
where Self: Immutable,

Writes a copy of self to dst. Read more
Source§

fn write_to_prefix( &self, dst: &mut [u8], ) -> Result<(), SizeError<&Self, &mut [u8]>>
where Self: Immutable,

Writes a copy of self to the prefix of dst. Read more
Source§

fn write_to_suffix( &self, dst: &mut [u8], ) -> Result<(), SizeError<&Self, &mut [u8]>>
where Self: Immutable,

Writes a copy of self to the suffix of dst. Read more
Source§

impl Mul for Ratio

Source§

type Output = Ratio

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Ratio> for i64

Source§

type Output = i64

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Ratio) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<i64> for Ratio

Source§

type Output = i64

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: i64) -> Self::Output

Performs the * operation. Read more
Source§

impl PartialEq for Ratio

Source§

fn eq(&self, other: &Ratio) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable)§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Ratio

Source§

impl TryFromBytes for Ratio
where u32: TryFromBytes,

Source§

fn try_read_from_bytes( source: &[u8], ) -> Result<Self, ConvertError<!, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: Sized,

Attempts to read the given source as a Self. Read more
Source§

fn try_read_from_prefix( source: &[u8], ) -> Result<(Self, &[u8]), ConvertError<!, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: Sized,

Attempts to read a Self from the prefix of the given source. Read more
Source§

fn try_read_from_suffix( source: &[u8], ) -> Result<(&[u8], Self), ConvertError<!, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: Sized,

Attempts to read a Self from the suffix of the given source. Read more

Auto Trait Implementations§

§

impl Freeze for Ratio

§

impl RefUnwindSafe for Ratio

§

impl Send for Ratio

§

impl Sync for Ratio

§

impl Unpin for Ratio

§

impl UnsafeUnpin for Ratio

§

impl UnwindSafe for Ratio

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

Source§

impl<T> ToMutPtr for T
where T: ?Sized,

Source§

type Target = T

The target type of the pointer.
Source§

fn to_mut_ptr(&self) -> *mut T

Casts the reference to a mutable raw pointer.
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = !

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.