[−][src]Struct embedded_time::Fraction
A fractional value
Used primarily to define the scaling factor for the Duration, Rate, Instant and
Clock traits and types.
Implementations
impl Fraction[src]
pub const fn new(numerator: u32, denominator: u32) -> Self[src]
Construct a new Fraction.
A reduction is not performed. Also there is no check for a denominator of 0. If these
features are needed, use Fraction::new_reduce()
pub const fn numerator(&self) -> &u32[src]
Return the numerator of the fraction
pub const fn denominator(&self) -> &u32[src]
Return the denominator of the fraction
impl Fraction[src]
pub fn new_reduce(
numerator: u32,
denominator: u32
) -> Result<Self, ConversionError>[src]
numerator: u32,
denominator: u32
) -> Result<Self, ConversionError>
Construct a new Fraction.
A reduction and denominator == 0 check are performed.
Errors
ConversionError::DivByZero : A 0 denominator was detected
pub fn to_integer(&self) -> u32[src]
Returns the value truncated to an integer
pub fn from_integer(value: u32) -> Self[src]
Constructs a Fraction from an integer.
Equivalent to Fraction::new(value,1).
pub fn recip(self) -> Self[src]
Returns the reciprocal of the fraction
pub fn checked_mul(&self, v: &Self) -> Result<Self, ConversionError>[src]
Checked Fraction × Fraction = Fraction
Examples
assert_eq!(Fraction::new(1000, 1).checked_mul(&Fraction::new(5,5)), Ok(Fraction::new(5_000, 5))); assert_eq!(Fraction::new(u32::MAX, 1).checked_mul(&Fraction::new(2,1)), Err(ConversionError::Overflow));
Errors
pub fn checked_div(&self, v: &Self) -> Result<Self, ConversionError>[src]
Checked Fraction / Fraction = Fraction
Examples
assert_eq!(Fraction::new(1000, 1).checked_div(&Fraction::new(10, 1000)), Ok(Fraction::new(1_000_000, 10))); assert_eq!(Fraction::new(1, u32::MAX).checked_div(&Fraction::new(2,1)), Err(ConversionError::Overflow));
Errors
pub fn checked_mul_integer(
&self,
multiplier: u32
) -> Result<Self, ConversionError>[src]
&self,
multiplier: u32
) -> Result<Self, ConversionError>
Checked Fraction × integer = Fraction
Examples
assert_eq!(Fraction::new(1000, 1).checked_mul_integer(5_u32), Ok(Fraction::new(5_000, 1))); assert_eq!(Fraction::new(u32::MAX, 1).checked_mul_integer(2_u32), Err(ConversionError::Overflow));
Errors
pub fn checked_div_integer(&self, divisor: u32) -> Result<Self, ConversionError>[src]
Checked Fraction / integer = Fraction
Examples
assert_eq!(Fraction::new(1000, 1).checked_div_integer(5_u32), Ok(Fraction::new(200, 1))); assert_eq!(Fraction::new(1, 1000).checked_div_integer(5_u32), Ok(Fraction::new(1, 5000))); assert_eq!(Fraction::new(1, u32::MAX).checked_div_integer(2_u32), Err(ConversionError::Overflow));
Errors
Trait Implementations
impl Clone for Fraction[src]
impl Copy for Fraction[src]
impl Debug for Fraction[src]
impl Div<Fraction> for Fraction[src]
type Output = Self
The resulting type after applying the / operator.
fn div(self, rhs: Self) -> Self::Output[src]
impl Eq for Fraction[src]
impl Mul<Fraction> for Fraction[src]
type Output = Self
The resulting type after applying the * operator.
fn mul(self, rhs: Self) -> Self::Output[src]
impl Ord for Fraction[src]
fn cmp(&self, other: &Fraction) -> Ordering[src]
#[must_use]fn max(self, other: Self) -> Self1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self[src]
impl PartialEq<Fraction> for Fraction[src]
impl PartialOrd<Fraction> for Fraction[src]
fn partial_cmp(&self, other: &Fraction) -> Option<Ordering>[src]
fn lt(&self, other: &Fraction) -> bool[src]
fn le(&self, other: &Fraction) -> bool[src]
fn gt(&self, other: &Fraction) -> bool[src]
fn ge(&self, other: &Fraction) -> bool[src]
impl StructuralEq for Fraction[src]
impl StructuralPartialEq for Fraction[src]
Auto Trait Implementations
impl RefUnwindSafe for Fraction
impl Send for Fraction
impl Sync for Fraction
impl Unpin for Fraction
impl UnwindSafe for Fraction
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T[src]
fn clone_into(&self, target: &mut T)[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,