pub struct Rational {
pub numerator: i64,
pub denominator: i64,
}Expand description
Exact rational number for arithmetic during Fourier-Motzkin elimination.
Rationals are automatically normalized to lowest terms with positive denominator. This ensures consistent comparison and canonical representation.
§Invariants
denominator > 0(sign carried by numerator)gcd(|numerator|, denominator) = 1(lowest terms)
Fields§
§numerator: i64The numerator (may be negative).
denominator: i64The denominator (always positive, never zero).
Implementations§
Source§impl Rational
impl Rational
Sourcepub fn new(n: i64, d: i64) -> Self
pub fn new(n: i64, d: i64) -> Self
Create a new rational, automatically normalizing to lowest terms
Sourcepub fn div(&self, other: &Rational) -> Option<Rational>
pub fn div(&self, other: &Rational) -> Option<Rational>
Divide two rationals (returns None if dividing by zero)
Sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Check if negative
Sourcepub fn is_positive(&self) -> bool
pub fn is_positive(&self) -> bool
Check if positive
Trait Implementations§
Source§impl Ord for Rational
impl Ord for Rational
Source§impl PartialOrd for Rational
impl PartialOrd for Rational
impl Eq for Rational
impl StructuralPartialEq for Rational
Auto Trait Implementations§
impl Freeze for Rational
impl RefUnwindSafe for Rational
impl Send for Rational
impl Sync for Rational
impl Unpin for Rational
impl UnwindSafe for Rational
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