pub struct URational { /* private fields */ }Expand description
A type representing an unsigned projectively-extended rational number
Subtracting a large number from a smaller one always returns 0 unless
the larger number is ∞.
§Examples
use extended_rational::URational;
let a = URational::new(3, 17);
let b = URational::new(4, 7);
assert_eq!(a+b, URational::new(89, 119));Use the uratio! macro for more convenient use.
let a = uratio!(3, 17);
let b = uratio!(4, 7);Or for easy conversions from primitive types.
let a = uratio!(343.863);
let b = uratio!(2u8);Implementations§
Source§impl URational
impl URational
Sourcepub fn new(numerator: u64, denominator: u64) -> URational
pub fn new(numerator: u64, denominator: u64) -> URational
Create a new unsigned rational with the given numerator and denominator.
Sourcepub fn numerator_mut(&mut self) -> &mut u64
pub fn numerator_mut(&mut self) -> &mut u64
Returns the numerator of this rational mutably.
Sourcepub fn denominator(self) -> u64
pub fn denominator(self) -> u64
Returns the denominator of this rational.
Sourcepub fn denominator_mut(&mut self) -> &mut u64
pub fn denominator_mut(&mut self) -> &mut u64
Returns the denominator of this rational mutably.
Sourcepub fn min_pos_value() -> URational
pub fn min_pos_value() -> URational
Returns the smallest non-zero value an unsigned rational can store.
Sourcepub fn is_infinity(self) -> bool
pub fn is_infinity(self) -> bool
Returns true if this rational is ∞ and false otherwise.
Sourcepub fn is_signed(self) -> bool
pub fn is_signed(self) -> bool
Returns true if this rational is a signed number (not NaN, 0, or ∞) and false otherwise.
Sourcepub fn reciprocal(self) -> URational
pub fn reciprocal(self) -> URational
Returns the reciprocal of this rational.
Sourcepub fn complexity(self) -> u64
pub fn complexity(self) -> u64
Returns the complexity of this rational (max of numerator and denominator).
Sourcepub fn floor(self) -> URational
pub fn floor(self) -> URational
Returns this rational with no fractional component by rounding down.
Sourcepub fn round(self) -> URational
pub fn round(self) -> URational
Returns this rational with no fractional component by rounding.
Sourcepub fn ceil(self) -> URational
pub fn ceil(self) -> URational
Returns this rational with no fractional component by rounding up.
Sourcepub fn add_exact(self, other: URational) -> Option<URational>
pub fn add_exact(self, other: URational) -> Option<URational>
Computes self + other, returning None if rounding occurred.
Sourcepub fn sub_exact(self, other: URational) -> Option<URational>
pub fn sub_exact(self, other: URational) -> Option<URational>
Computes self - other, returning None if rounding occurred.
Sourcepub fn mul_exact(self, other: URational) -> Option<URational>
pub fn mul_exact(self, other: URational) -> Option<URational>
Computes self * other, returning None if rounding occurred.
Trait Implementations§
Source§impl AddAssign for URational
impl AddAssign for URational
Source§fn add_assign(&mut self, other: URational)
fn add_assign(&mut self, other: URational)
+= operation. Read moreSource§impl DivAssign for URational
impl DivAssign for URational
Source§fn div_assign(&mut self, other: URational)
fn div_assign(&mut self, other: URational)
/= operation. Read moreSource§impl MulAssign for URational
impl MulAssign for URational
Source§fn mul_assign(&mut self, other: URational)
fn mul_assign(&mut self, other: URational)
*= operation. Read moreSource§impl PartialOrd for URational
impl PartialOrd for URational
Source§impl RemAssign for URational
impl RemAssign for URational
Source§fn rem_assign(&mut self, other: URational)
fn rem_assign(&mut self, other: URational)
%= operation. Read moreSource§impl SubAssign for URational
impl SubAssign for URational
Source§fn sub_assign(&mut self, other: URational)
fn sub_assign(&mut self, other: URational)
-= operation. Read more