[−][src]Struct num_decimal::Num
An unlimited precision number type with some improvements and
customizations over BigRational
.
Implementations
impl Num
[src]
pub fn new<T, U>(numer: T, denom: U) -> Self where
BigInt: From<T>,
BigInt: From<U>,
[src]
BigInt: From<T>,
BigInt: From<U>,
Construct a Num
from two integers.
pub fn round(&self) -> Self
[src]
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.
pub fn round_with(&self, precision: usize) -> Self
[src]
Round the given Num
with the given precision.
Rounding happens based on the Round-Half-To-Even scheme similar to
round
.
pub fn trunc(&self) -> Self
[src]
Round the given Num
towards zero.
pub fn fract(&self) -> Self
[src]
Return the fractional part of the given Num
, with division rounded towards zero.
pub fn to_integer(&self) -> BigInt
[src]
Convert the given Num
to an integer, rounding towards zero.
pub fn to_i64(&self) -> Option<i64>
[src]
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.
pub fn to_u64(&self) -> Option<u64>
[src]
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.
pub fn to_f64(&self) -> Option<f64>
[src]
Convert the given Num
into a f64
.
None
is returned if the numerator or the denominator cannot be
converted into an f64
.
pub fn is_zero(&self) -> bool
[src]
Check if the given Num
is zero.
pub fn is_positive(&self) -> bool
[src]
Check if the given Num
is positive.
pub fn is_negative(&self) -> bool
[src]
Check if the given Num
is negative.
pub fn display(&self) -> CustomDisplay
[src]
Retrieve a display adapter that can be used for some more elaborate formatting needs.
Trait Implementations
impl<'_> Add<&'_ Num> for Num
[src]
type Output = Num
The resulting type after applying the +
operator.
fn add(self, rhs: &Num) -> Self::Output
[src]
impl<'_, '_> Add<&'_ Num> for &'_ Num
[src]
type Output = Num
The resulting type after applying the +
operator.
fn add(self, rhs: &Num) -> Self::Output
[src]
impl Add<Num> for Num
[src]
type Output = Num
The resulting type after applying the +
operator.
fn add(self, rhs: Num) -> Self::Output
[src]
impl<'_> Add<Num> for &'_ Num
[src]
type Output = Num
The resulting type after applying the +
operator.
fn add(self, rhs: Num) -> Self::Output
[src]
impl<T> Add<T> for Num where
BigInt: From<T>,
[src]
BigInt: From<T>,
type Output = Num
The resulting type after applying the +
operator.
fn add(self, rhs: T) -> Self::Output
[src]
impl<'_, T> Add<T> for &'_ Num where
BigInt: From<T>,
[src]
BigInt: From<T>,
type Output = Num
The resulting type after applying the +
operator.
fn add(self, rhs: T) -> Self::Output
[src]
impl<'_> AddAssign<&'_ Num> for Num
[src]
fn add_assign(&mut self, rhs: &Num)
[src]
impl AddAssign<Num> for Num
[src]
fn add_assign(&mut self, rhs: Num)
[src]
impl<T> AddAssign<T> for Num where
BigInt: From<T>,
[src]
BigInt: From<T>,
fn add_assign(&mut self, rhs: T)
[src]
impl Clone for Num
[src]
impl Debug for Num
[src]
impl Default for Num
[src]
impl Display for Num
[src]
impl<'_> Div<&'_ Num> for Num
[src]
type Output = Num
The resulting type after applying the /
operator.
fn div(self, rhs: &Num) -> Self::Output
[src]
impl<'_, '_> Div<&'_ Num> for &'_ Num
[src]
type Output = Num
The resulting type after applying the /
operator.
fn div(self, rhs: &Num) -> Self::Output
[src]
impl Div<Num> for Num
[src]
type Output = Num
The resulting type after applying the /
operator.
fn div(self, rhs: Num) -> Self::Output
[src]
impl<'_> Div<Num> for &'_ Num
[src]
type Output = Num
The resulting type after applying the /
operator.
fn div(self, rhs: Num) -> Self::Output
[src]
impl<T> Div<T> for Num where
BigInt: From<T>,
[src]
BigInt: From<T>,
type Output = Num
The resulting type after applying the /
operator.
fn div(self, rhs: T) -> Self::Output
[src]
impl<'_, T> Div<T> for &'_ Num where
BigInt: From<T>,
[src]
BigInt: From<T>,
type Output = Num
The resulting type after applying the /
operator.
fn div(self, rhs: T) -> Self::Output
[src]
impl<'_> DivAssign<&'_ Num> for Num
[src]
fn div_assign(&mut self, rhs: &Num)
[src]
impl DivAssign<Num> for Num
[src]
fn div_assign(&mut self, rhs: Num)
[src]
impl<T> DivAssign<T> for Num where
BigInt: From<T>,
[src]
BigInt: From<T>,
fn div_assign(&mut self, rhs: T)
[src]
impl Eq for Num
[src]
impl From<BigInt> for Num
[src]
impl From<i128> for Num
[src]
impl From<i16> for Num
[src]
impl From<i32> for Num
[src]
impl From<i64> for Num
[src]
impl From<i8> for Num
[src]
impl From<isize> for Num
[src]
impl From<u128> for Num
[src]
impl From<u16> for Num
[src]
impl From<u32> for Num
[src]
impl From<u64> for Num
[src]
impl From<u8> for Num
[src]
impl From<usize> for Num
[src]
impl FromStr for Num
[src]
type Err = ParseNumError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, Self::Err>
[src]
impl Hash for Num
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<'_> Mul<&'_ Num> for Num
[src]
type Output = Num
The resulting type after applying the *
operator.
fn mul(self, rhs: &Num) -> Self::Output
[src]
impl<'_, '_> Mul<&'_ Num> for &'_ Num
[src]
type Output = Num
The resulting type after applying the *
operator.
fn mul(self, rhs: &Num) -> Self::Output
[src]
impl Mul<Num> for Num
[src]
type Output = Num
The resulting type after applying the *
operator.
fn mul(self, rhs: Num) -> Self::Output
[src]
impl<'_> Mul<Num> for &'_ Num
[src]
type Output = Num
The resulting type after applying the *
operator.
fn mul(self, rhs: Num) -> Self::Output
[src]
impl<T> Mul<T> for Num where
BigInt: From<T>,
[src]
BigInt: From<T>,
type Output = Num
The resulting type after applying the *
operator.
fn mul(self, rhs: T) -> Self::Output
[src]
impl<'_, T> Mul<T> for &'_ Num where
BigInt: From<T>,
[src]
BigInt: From<T>,
type Output = Num
The resulting type after applying the *
operator.
fn mul(self, rhs: T) -> Self::Output
[src]
impl<'_> MulAssign<&'_ Num> for Num
[src]
fn mul_assign(&mut self, rhs: &Num)
[src]
impl MulAssign<Num> for Num
[src]
fn mul_assign(&mut self, rhs: Num)
[src]
impl<T> MulAssign<T> for Num where
BigInt: From<T>,
[src]
BigInt: From<T>,
fn mul_assign(&mut self, rhs: T)
[src]
impl Neg for Num
[src]
type Output = Num
The resulting type after applying the -
operator.
fn neg(self) -> Self::Output
[src]
impl<'_> Neg for &'_ Num
[src]
type Output = Num
The resulting type after applying the -
operator.
fn neg(self) -> Self::Output
[src]
impl Ord for Num
[src]
fn cmp(&self, other: &Num) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<Num> for Num
[src]
impl PartialOrd<Num> for Num
[src]
fn partial_cmp(&self, other: &Num) -> Option<Ordering>
[src]
fn lt(&self, other: &Num) -> bool
[src]
fn le(&self, other: &Num) -> bool
[src]
fn gt(&self, other: &Num) -> bool
[src]
fn ge(&self, other: &Num) -> bool
[src]
impl<'_> Rem<&'_ Num> for Num
[src]
type Output = Num
The resulting type after applying the %
operator.
fn rem(self, rhs: &Num) -> Self::Output
[src]
impl<'_, '_> Rem<&'_ Num> for &'_ Num
[src]
type Output = Num
The resulting type after applying the %
operator.
fn rem(self, rhs: &Num) -> Self::Output
[src]
impl Rem<Num> for Num
[src]
type Output = Num
The resulting type after applying the %
operator.
fn rem(self, rhs: Num) -> Self::Output
[src]
impl<'_> Rem<Num> for &'_ Num
[src]
type Output = Num
The resulting type after applying the %
operator.
fn rem(self, rhs: Num) -> Self::Output
[src]
impl<T> Rem<T> for Num where
BigInt: From<T>,
[src]
BigInt: From<T>,
type Output = Num
The resulting type after applying the %
operator.
fn rem(self, rhs: T) -> Self::Output
[src]
impl<'_, T> Rem<T> for &'_ Num where
BigInt: From<T>,
[src]
BigInt: From<T>,
type Output = Num
The resulting type after applying the %
operator.
fn rem(self, rhs: T) -> Self::Output
[src]
impl<'_> RemAssign<&'_ Num> for Num
[src]
fn rem_assign(&mut self, rhs: &Num)
[src]
impl RemAssign<Num> for Num
[src]
fn rem_assign(&mut self, rhs: Num)
[src]
impl<T> RemAssign<T> for Num where
BigInt: From<T>,
[src]
BigInt: From<T>,
fn rem_assign(&mut self, rhs: T)
[src]
impl StructuralEq for Num
[src]
impl StructuralPartialEq for Num
[src]
impl<'_> Sub<&'_ Num> for Num
[src]
type Output = Num
The resulting type after applying the -
operator.
fn sub(self, rhs: &Num) -> Self::Output
[src]
impl<'_, '_> Sub<&'_ Num> for &'_ Num
[src]
type Output = Num
The resulting type after applying the -
operator.
fn sub(self, rhs: &Num) -> Self::Output
[src]
impl Sub<Num> for Num
[src]
type Output = Num
The resulting type after applying the -
operator.
fn sub(self, rhs: Num) -> Self::Output
[src]
impl<'_> Sub<Num> for &'_ Num
[src]
type Output = Num
The resulting type after applying the -
operator.
fn sub(self, rhs: Num) -> Self::Output
[src]
impl<T> Sub<T> for Num where
BigInt: From<T>,
[src]
BigInt: From<T>,
type Output = Num
The resulting type after applying the -
operator.
fn sub(self, rhs: T) -> Self::Output
[src]
impl<'_, T> Sub<T> for &'_ Num where
BigInt: From<T>,
[src]
BigInt: From<T>,
type Output = Num
The resulting type after applying the -
operator.
fn sub(self, rhs: T) -> Self::Output
[src]
impl<'_> SubAssign<&'_ Num> for Num
[src]
fn sub_assign(&mut self, rhs: &Num)
[src]
impl SubAssign<Num> for Num
[src]
fn sub_assign(&mut self, rhs: Num)
[src]
impl<T> SubAssign<T> for Num where
BigInt: From<T>,
[src]
BigInt: From<T>,
fn sub_assign(&mut self, rhs: T)
[src]
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
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, Rhs> NumAssignOps<Rhs> for T where
T: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs>,
[src]
T: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs>,
impl<T, Rhs, Output> NumOps<Rhs, Output> for T where
T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,
[src]
T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,
impl<T, Base> RefNum<Base> for T where
T: NumOps<Base, Base> + for<'r> NumOps<&'r Base, Base>,
[src]
T: NumOps<Base, Base> + for<'r> NumOps<&'r Base, Base>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,