Struct num_decimal::Num
source · [−]pub struct Num(_);
Expand description
An unlimited precision number type with some improvements and
customizations over BigRational
.
Implementations
sourceimpl Num
impl Num
sourcepub fn round(&self) -> Self
pub fn round(&self) -> Self
Round the given Num
to the nearest integer.
Rounding happens based on the Round-Half-To-Even scheme (also known as the “bankers rounding” algorithm), which rounds to the closest integer as expected but if the fractional part is exactly 1/2 (i.e., equidistant from two integers) it rounds to the even one of the two.
sourcepub fn round_with(&self, precision: usize) -> Self
pub fn round_with(&self, precision: usize) -> Self
Round the given Num
with the given precision.
Rounding happens based on the Round-Half-To-Even scheme similar to
round
.
sourcepub fn fract(&self) -> Self
pub fn fract(&self) -> Self
Return the fractional part of the given Num
, with division rounded towards zero.
sourcepub fn to_integer(&self) -> BigInt
pub fn to_integer(&self) -> BigInt
Convert the given Num
to an integer, rounding towards zero.
sourcepub fn to_i64(&self) -> Option<i64>
pub fn to_i64(&self) -> Option<i64>
Convert the given Num
into a u64
.
The value will be converted into an integer, with rounding towards
zero. None
is returned if the resulting integer does not fit
into 64 bit.
sourcepub fn to_u64(&self) -> Option<u64>
pub fn to_u64(&self) -> Option<u64>
Convert the given Num
into a u64
.
The value will be converted into an integer, with rounding towards
zero. None
is returned if the resulting integer does not fit
into 64 bit.
sourcepub fn to_f64(&self) -> Option<f64>
pub fn to_f64(&self) -> Option<f64>
Convert the given Num
into a f64
.
None
is returned if the numerator or the denominator cannot be
converted into an f64
.
sourcepub fn is_positive(&self) -> bool
pub fn is_positive(&self) -> bool
Check if the given Num
is positive.
sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Check if the given Num
is negative.
sourcepub fn display(&self) -> CustomDisplay<'_>
pub fn display(&self) -> CustomDisplay<'_>
Retrieve a display adapter that can be used for some more elaborate formatting needs.
Trait Implementations
sourceimpl AddAssign<&'_ Num> for Num
impl AddAssign<&'_ Num> for Num
sourcefn add_assign(&mut self, rhs: &Num)
fn add_assign(&mut self, rhs: &Num)
Performs the +=
operation. Read more
sourceimpl AddAssign<Num> for Num
impl AddAssign<Num> for Num
sourcefn add_assign(&mut self, rhs: Num)
fn add_assign(&mut self, rhs: Num)
Performs the +=
operation. Read more
sourceimpl<T> AddAssign<T> for Num where
BigInt: From<T>,
impl<T> AddAssign<T> for Num where
BigInt: From<T>,
sourcefn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
Performs the +=
operation. Read more
sourceimpl DivAssign<&'_ Num> for Num
impl DivAssign<&'_ Num> for Num
sourcefn div_assign(&mut self, rhs: &Num)
fn div_assign(&mut self, rhs: &Num)
Performs the /=
operation. Read more
sourceimpl DivAssign<Num> for Num
impl DivAssign<Num> for Num
sourcefn div_assign(&mut self, rhs: Num)
fn div_assign(&mut self, rhs: Num)
Performs the /=
operation. Read more
sourceimpl<T> DivAssign<T> for Num where
BigInt: From<T>,
impl<T> DivAssign<T> for Num where
BigInt: From<T>,
sourcefn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
Performs the /=
operation. Read more
sourceimpl MulAssign<&'_ Num> for Num
impl MulAssign<&'_ Num> for Num
sourcefn mul_assign(&mut self, rhs: &Num)
fn mul_assign(&mut self, rhs: &Num)
Performs the *=
operation. Read more
sourceimpl MulAssign<Num> for Num
impl MulAssign<Num> for Num
sourcefn mul_assign(&mut self, rhs: Num)
fn mul_assign(&mut self, rhs: Num)
Performs the *=
operation. Read more
sourceimpl<T> MulAssign<T> for Num where
BigInt: From<T>,
impl<T> MulAssign<T> for Num where
BigInt: From<T>,
sourcefn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
Performs the *=
operation. Read more
sourceimpl Ord for Num
impl Ord for Num
sourceimpl PartialOrd<Num> for Num
impl PartialOrd<Num> for Num
sourcefn partial_cmp(&self, other: &Num) -> Option<Ordering>
fn partial_cmp(&self, other: &Num) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl RemAssign<&'_ Num> for Num
impl RemAssign<&'_ Num> for Num
sourcefn rem_assign(&mut self, rhs: &Num)
fn rem_assign(&mut self, rhs: &Num)
Performs the %=
operation. Read more
sourceimpl RemAssign<Num> for Num
impl RemAssign<Num> for Num
sourcefn rem_assign(&mut self, rhs: Num)
fn rem_assign(&mut self, rhs: Num)
Performs the %=
operation. Read more
sourceimpl<T> RemAssign<T> for Num where
BigInt: From<T>,
impl<T> RemAssign<T> for Num where
BigInt: From<T>,
sourcefn rem_assign(&mut self, rhs: T)
fn rem_assign(&mut self, rhs: T)
Performs the %=
operation. Read more
sourceimpl SubAssign<&'_ Num> for Num
impl SubAssign<&'_ Num> for Num
sourcefn sub_assign(&mut self, rhs: &Num)
fn sub_assign(&mut self, rhs: &Num)
Performs the -=
operation. Read more
sourceimpl SubAssign<Num> for Num
impl SubAssign<Num> for Num
sourcefn sub_assign(&mut self, rhs: Num)
fn sub_assign(&mut self, rhs: Num)
Performs the -=
operation. Read more
sourceimpl<T> SubAssign<T> for Num where
BigInt: From<T>,
impl<T> SubAssign<T> for Num where
BigInt: From<T>,
sourcefn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
Performs the -=
operation. Read more
impl Eq for Num
impl StructuralEq for Num
impl StructuralPartialEq for Num
Auto Trait Implementations
impl RefUnwindSafe for Num
impl Send for Num
impl Sync for Num
impl Unpin for Num
impl UnwindSafe for Num
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more