pub struct Fraction(/* private fields */);
Expand description
Implementations§
Source§impl Fraction
impl Fraction
Sourcepub const fn new(numerator: u32, denominator: u32) -> Self
pub const fn new(numerator: u32, denominator: u32) -> Self
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()
Sourcepub const fn denominator(&self) -> &u32
pub const fn denominator(&self) -> &u32
Return the denominator of the fraction
Source§impl Fraction
impl Fraction
Sourcepub fn new_reduce(
numerator: u32,
denominator: u32,
) -> Result<Self, ConversionError>
pub fn new_reduce( 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
Sourcepub fn to_integer(&self) -> u32
pub fn to_integer(&self) -> u32
Returns the value truncated to an integer
Sourcepub fn from_integer(value: u32) -> Self
pub fn from_integer(value: u32) -> Self
Constructs a Fraction
from an integer.
Equivalent to Fraction::new(value,1)
.
Sourcepub fn checked_mul(&self, v: &Self) -> Option<Self>
pub fn checked_mul(&self, v: &Self) -> Option<Self>
Sourcepub fn checked_div(&self, v: &Self) -> Option<Self>
pub fn checked_div(&self, v: &Self) -> Option<Self>
Trait Implementations§
Source§impl Ord for Fraction
impl Ord for Fraction
Source§impl PartialOrd for Fraction
impl PartialOrd for Fraction
impl Copy for Fraction
impl Eq for Fraction
impl StructuralPartialEq for Fraction
Auto Trait Implementations§
impl Freeze for Fraction
impl RefUnwindSafe for Fraction
impl Send for Fraction
impl Sync for Fraction
impl Unpin for Fraction
impl UnwindSafe for Fraction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more