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) · Source§

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 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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Ratio

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§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

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.
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.