pub struct ExactRational { /* private fields */ }Expand description
Implementations§
Source§impl ExactRational
impl ExactRational
Sourcepub fn new(num: ExactNum, den: ExactNum) -> Self
pub fn new(num: ExactNum, den: ExactNum) -> Self
num/den reduced to lowest terms. Negative den moves the sign to num.
Zero den or a non-finite part is NaN.
Sourcepub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
True if the denominator is 1.
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 round(&self) -> Self
pub fn round(&self) -> Self
Nearest integer, ties away from zero, as a rational with denominator 1.
Sourcepub fn parse_exact(s: &str) -> Option<Self>
pub fn parse_exact(s: &str) -> Option<Self>
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: &Self) -> Option<Ordering>
pub fn partial_cmp(&self, other: &Self) -> 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
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
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
Mutably borrows from an owned value. Read more
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> ⓘ
Converts
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> ⓘ
Converts
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