[][src]Struct num_decimal::Num

pub struct 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]

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.

impl<'_, '_> Add<&'_ Num> for &'_ Num[src]

type Output = Num

The resulting type after applying the + operator.

impl Add<Num> for Num[src]

type Output = Num

The resulting type after applying the + operator.

impl<'_> Add<Num> for &'_ Num[src]

type Output = Num

The resulting type after applying the + operator.

impl<T> Add<T> for Num where
    BigInt: From<T>, 
[src]

type Output = Num

The resulting type after applying the + operator.

impl<'_, T> Add<T> for &'_ Num where
    BigInt: From<T>, 
[src]

type Output = Num

The resulting type after applying the + operator.

impl<'_> AddAssign<&'_ Num> for Num[src]

impl AddAssign<Num> for Num[src]

impl<T> AddAssign<T> for Num where
    BigInt: From<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.

impl<'_, '_> Div<&'_ Num> for &'_ Num[src]

type Output = Num

The resulting type after applying the / operator.

impl Div<Num> for Num[src]

type Output = Num

The resulting type after applying the / operator.

impl<'_> Div<Num> for &'_ Num[src]

type Output = Num

The resulting type after applying the / operator.

impl<T> Div<T> for Num where
    BigInt: From<T>, 
[src]

type Output = Num

The resulting type after applying the / operator.

impl<'_, T> Div<T> for &'_ Num where
    BigInt: From<T>, 
[src]

type Output = Num

The resulting type after applying the / operator.

impl<'_> DivAssign<&'_ Num> for Num[src]

impl DivAssign<Num> for Num[src]

impl<T> DivAssign<T> for Num where
    BigInt: From<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.

impl Hash for Num[src]

impl<'_> Mul<&'_ Num> for Num[src]

type Output = Num

The resulting type after applying the * operator.

impl<'_, '_> Mul<&'_ Num> for &'_ Num[src]

type Output = Num

The resulting type after applying the * operator.

impl Mul<Num> for Num[src]

type Output = Num

The resulting type after applying the * operator.

impl<'_> Mul<Num> for &'_ Num[src]

type Output = Num

The resulting type after applying the * operator.

impl<T> Mul<T> for Num where
    BigInt: From<T>, 
[src]

type Output = Num

The resulting type after applying the * operator.

impl<'_, T> Mul<T> for &'_ Num where
    BigInt: From<T>, 
[src]

type Output = Num

The resulting type after applying the * operator.

impl<'_> MulAssign<&'_ Num> for Num[src]

impl MulAssign<Num> for Num[src]

impl<T> MulAssign<T> for Num where
    BigInt: From<T>, 
[src]

impl Neg for Num[src]

type Output = Num

The resulting type after applying the - operator.

impl<'_> Neg for &'_ Num[src]

type Output = Num

The resulting type after applying the - operator.

impl Ord for Num[src]

impl PartialEq<Num> for Num[src]

impl PartialOrd<Num> for Num[src]

impl<'_> Rem<&'_ Num> for Num[src]

type Output = Num

The resulting type after applying the % operator.

impl<'_, '_> Rem<&'_ Num> for &'_ Num[src]

type Output = Num

The resulting type after applying the % operator.

impl Rem<Num> for Num[src]

type Output = Num

The resulting type after applying the % operator.

impl<'_> Rem<Num> for &'_ Num[src]

type Output = Num

The resulting type after applying the % operator.

impl<T> Rem<T> for Num where
    BigInt: From<T>, 
[src]

type Output = Num

The resulting type after applying the % operator.

impl<'_, T> Rem<T> for &'_ Num where
    BigInt: From<T>, 
[src]

type Output = Num

The resulting type after applying the % operator.

impl<'_> RemAssign<&'_ Num> for Num[src]

impl RemAssign<Num> for Num[src]

impl<T> RemAssign<T> for Num where
    BigInt: From<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.

impl<'_, '_> Sub<&'_ Num> for &'_ Num[src]

type Output = Num

The resulting type after applying the - operator.

impl Sub<Num> for Num[src]

type Output = Num

The resulting type after applying the - operator.

impl<'_> Sub<Num> for &'_ Num[src]

type Output = Num

The resulting type after applying the - operator.

impl<T> Sub<T> for Num where
    BigInt: From<T>, 
[src]

type Output = Num

The resulting type after applying the - operator.

impl<'_, T> Sub<T> for &'_ Num where
    BigInt: From<T>, 
[src]

type Output = Num

The resulting type after applying the - operator.

impl<'_> SubAssign<&'_ Num> for Num[src]

impl SubAssign<Num> for Num[src]

impl<T> SubAssign<T> for Num where
    BigInt: From<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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, Rhs> NumAssignOps<Rhs> for T where
    T: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs>, 
[src]

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]

impl<T, Base> RefNum<Base> for T where
    T: NumOps<Base, Base> + for<'r> NumOps<&'r Base, Base>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.