pub struct Rat { /* private fields */ }Expand description
A rational number in lowest terms; the denominator is always positive and never zero.
Implementations§
Source§impl Rat
impl Rat
Sourcepub fn new(num: BigInt, den: BigInt) -> Option<Rat>
pub fn new(num: BigInt, den: BigInt) -> Option<Rat>
num / den, reduced. None when the denominator is zero: an infinite
rational is not a rational, and the caller answers in floats.
pub fn from_int(v: BigInt) -> Rat
pub fn zero() -> Rat
pub fn one() -> Rat
pub fn numer(&self) -> &BigInt
pub fn denom(&self) -> &BigInt
pub fn is_zero(&self) -> bool
pub fn is_integer(&self) -> bool
pub fn to_f64(&self) -> f64
pub fn neg(&self) -> Rat
pub fn abs(&self) -> Rat
Sourcepub fn signum(&self) -> BigInt
pub fn signum(&self) -> BigInt
-1, 0 or 1 as a whole number, which is the type J answers * with.
pub fn add(&self, other: &Rat) -> Rat
pub fn sub(&self, other: &Rat) -> Rat
pub fn mul(&self, other: &Rat) -> Rat
pub fn recip(&self) -> Option<Rat>
pub fn ceil(&self) -> BigInt
Trait Implementations§
Source§impl Display for Rat
The J spelling, with - where the language’s own negative sign goes:
3r4, and a whole value as the integer alone.
impl Display for Rat
The J spelling, with - where the language’s own negative sign goes:
3r4, and a whole value as the integer alone.
impl Eq for Rat
Source§impl Ord for Rat
impl Ord for Rat
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialOrd for Rat
impl PartialOrd for Rat
impl StructuralPartialEq for Rat
Auto Trait Implementations§
impl Freeze for Rat
impl RefUnwindSafe for Rat
impl Send for Rat
impl Sync for Rat
impl Unpin for Rat
impl UnsafeUnpin for Rat
impl UnwindSafe for Rat
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.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