pub struct ExactRational { /* private fields */ }Expand description
Implementations§
Source§impl ExactRational
impl ExactRational
Sourcepub fn new(num: ExactNum, den: ExactNum) -> ExactRational
pub fn new(num: ExactNum, den: ExactNum) -> ExactRational
num/den reduced to lowest terms. Negative den moves the sign to num.
Zero den or a non-finite part is NaN.
Sourcepub fn from_i64(n: i64, d: i64) -> ExactRational
pub fn from_i64(n: i64, d: i64) -> ExactRational
Integer ratio n/d at default limb precision.
Sourcepub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
True if the denominator is 1.
Sourcepub fn add(&self, rhs: &ExactRational) -> ExactRational
pub fn add(&self, rhs: &ExactRational) -> ExactRational
self + rhs as an exact rational.
Sourcepub fn sub(&self, rhs: &ExactRational) -> ExactRational
pub fn sub(&self, rhs: &ExactRational) -> ExactRational
self - rhs.
Sourcepub fn mul(&self, rhs: &ExactRational) -> ExactRational
pub fn mul(&self, rhs: &ExactRational) -> ExactRational
self * rhs.
Sourcepub fn div(&self, rhs: &ExactRational) -> ExactRational
pub fn div(&self, rhs: &ExactRational) -> ExactRational
self / rhs. Zero rhs is NaN.
Sourcepub fn to_exact_num(&self, p: usize, rm: RoundingMode) -> ExactNum
pub fn to_exact_num(&self, p: usize, rm: RoundingMode) -> ExactNum
Convert to an ExactNum at (p, rm).
Sourcepub fn floor(&self) -> ExactRational
pub fn floor(&self) -> ExactRational
Greatest integer ≤ self as a rational with denominator 1.
Sourcepub fn ceil(&self) -> ExactRational
pub fn ceil(&self) -> ExactRational
Least integer ≥ self as a rational with denominator 1.
Sourcepub fn round(&self) -> ExactRational
pub fn round(&self) -> ExactRational
Nearest integer, ties away from zero, as a rational with denominator 1.
Sourcepub fn from_ints(num: ExactInt, den: ExactInt) -> ExactRational
pub fn from_ints(num: ExactInt, den: ExactInt) -> ExactRational
Build num/den from limb integers.
Sourcepub fn parse_exact(s: &str) -> Option<ExactRational>
pub fn parse_exact(s: &str) -> Option<ExactRational>
Parse a decimal (optional e/E exponent) as an exact rational.
0.1 is 1/10, not a binary float. Invalid syntax is None.
Sourcepub fn format_exact(&self, rdx: Radix) -> Option<String>
pub fn format_exact(&self, rdx: Radix) -> Option<String>
Minimum digits in rdx for an exact terminating representation. None if the
denominator has a prime factor that does not divide the radix.
Sourcepub fn partial_cmp(&self, other: &ExactRational) -> Option<Ordering>
pub fn partial_cmp(&self, other: &ExactRational) -> Option<Ordering>
Exact comparison via cross-multiplication. None if either value is NaN.
Trait Implementations§
Source§impl Clone for ExactRational
impl Clone for ExactRational
Source§fn clone(&self) -> ExactRational
fn clone(&self) -> ExactRational
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ExactRational
impl Debug for ExactRational
Auto Trait Implementations§
impl Freeze for ExactRational
impl RefUnwindSafe for ExactRational
impl Send for ExactRational
impl Sync for ExactRational
impl Unpin for ExactRational
impl UnsafeUnpin for ExactRational
impl UnwindSafe for ExactRational
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more