Skip to main content

FromRatio

Trait FromRatio 

Source
pub trait FromRatio<T> {
    // Required method
    fn from_ratio(numerator: T, denominator: T) -> Self;

    // Provided method
    fn from_ratios<const N: usize>(
        numerators: [T; N],
        denominator: T,
    ) -> [Self; N]
       where T: Copy,
             Self: Sized { ... }
}
Expand description

Construct a value from the ratio of two raw values.

For positive F, Q<T, A, F> computes (numerator << F) / denominator in A, then narrows to T. The denominator must be nonzero and the result must fit T.

Required Methods§

Source

fn from_ratio(numerator: T, denominator: T) -> Self

Return numerator / denominator in Self’s representation.

Provided Methods§

Source

fn from_ratios<const N: usize>(numerators: [T; N], denominator: T) -> [Self; N]
where T: Copy, Self: Sized,

Divide several numerators by one denominator.

Implementations may prepare the denominator once; floating-point types multiply every numerator by one reciprocal.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl FromRatio<f32> for f32

Source§

fn from_ratio(numerator: f32, denominator: f32) -> Self

Source§

fn from_ratios<const N: usize>( numerators: [f32; N], denominator: f32, ) -> [Self; N]

Source§

impl FromRatio<f64> for f64

Source§

fn from_ratio(numerator: f64, denominator: f64) -> Self

Source§

fn from_ratios<const N: usize>( numerators: [f64; N], denominator: f64, ) -> [Self; N]

Implementors§

Source§

impl<T, A, const F: i8> FromRatio<T> for Q<T, A, F>
where T: Copy + Shift + Accu<A> + Div<Output = T>, A: Shift + Div<Output = A>,