pub struct Num(/* private fields */);
Expand description
An unlimited precision number type with some improvements and
customizations over BigRational
.
Implementations§
Source§impl 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§
Source§impl AddAssign<&Num> for Num
impl AddAssign<&Num> for Num
Source§fn add_assign(&mut self, rhs: &Num)
fn add_assign(&mut self, rhs: &Num)
+=
operation. Read moreSource§impl<T> AddAssign<T> for Num
impl<T> AddAssign<T> for Num
Source§fn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
+=
operation. Read moreSource§impl AddAssign for Num
impl AddAssign for Num
Source§fn add_assign(&mut self, rhs: Num)
fn add_assign(&mut self, rhs: Num)
+=
operation. Read moreSource§impl DivAssign<&Num> for Num
impl DivAssign<&Num> for Num
Source§fn div_assign(&mut self, rhs: &Num)
fn div_assign(&mut self, rhs: &Num)
/=
operation. Read moreSource§impl<T> DivAssign<T> for Num
impl<T> DivAssign<T> for Num
Source§fn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
/=
operation. Read moreSource§impl DivAssign for Num
impl DivAssign for Num
Source§fn div_assign(&mut self, rhs: Num)
fn div_assign(&mut self, rhs: Num)
/=
operation. Read moreSource§impl MulAssign<&Num> for Num
impl MulAssign<&Num> for Num
Source§fn mul_assign(&mut self, rhs: &Num)
fn mul_assign(&mut self, rhs: &Num)
*=
operation. Read moreSource§impl<T> MulAssign<T> for Num
impl<T> MulAssign<T> for Num
Source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
*=
operation. Read moreSource§impl MulAssign for Num
impl MulAssign for Num
Source§fn mul_assign(&mut self, rhs: Num)
fn mul_assign(&mut self, rhs: Num)
*=
operation. Read moreSource§impl Ord for Num
impl Ord for Num
Source§impl PartialOrd for Num
impl PartialOrd for Num
Source§impl RemAssign<&Num> for Num
impl RemAssign<&Num> for Num
Source§fn rem_assign(&mut self, rhs: &Num)
fn rem_assign(&mut self, rhs: &Num)
%=
operation. Read moreSource§impl<T> RemAssign<T> for Num
impl<T> RemAssign<T> for Num
Source§fn rem_assign(&mut self, rhs: T)
fn rem_assign(&mut self, rhs: T)
%=
operation. Read moreSource§impl RemAssign for Num
impl RemAssign for Num
Source§fn rem_assign(&mut self, rhs: Num)
fn rem_assign(&mut self, rhs: Num)
%=
operation. Read moreSource§impl SubAssign<&Num> for Num
impl SubAssign<&Num> for Num
Source§fn sub_assign(&mut self, rhs: &Num)
fn sub_assign(&mut self, rhs: &Num)
-=
operation. Read moreSource§impl<T> SubAssign<T> for Num
impl<T> SubAssign<T> for Num
Source§fn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
-=
operation. Read moreSource§impl SubAssign for Num
impl SubAssign for Num
Source§fn sub_assign(&mut self, rhs: Num)
fn sub_assign(&mut self, rhs: Num)
-=
operation. Read more