Struct decimal_rs::Decimal [−][src]
pub struct Decimal { /* fields omitted */ }
High precision decimal.
Implementations
impl Decimal
[src]
impl Decimal
[src]pub const ZERO: Decimal
[src]
Zero value, i.e. 0
.
pub const ONE: Decimal
[src]
i.e. 1
.
pub const unsafe fn from_parts_unchecked(
int_val: u128,
scale: i16,
negative: bool
) -> Decimal
[src]
int_val: u128,
scale: i16,
negative: bool
) -> Decimal
Creates a Decimal
from parts without boundary checking.
Safety
User have to guarantee that int_val
has at most 38 tens digits and scale
ranges from [-126, 130]
.
pub const fn from_parts(
int_val: u128,
scale: i16,
negative: bool
) -> Result<Decimal, DecimalConvertError>
[src]
int_val: u128,
scale: i16,
negative: bool
) -> Result<Decimal, DecimalConvertError>
Creates a Decimal
from parts.
int_val
has at most 38 tens digits, scale
ranges from [-126, 130]
.
pub const fn into_parts(self) -> (u128, i16, bool)
[src]
Consumes the Decimal
, returning (int_val, scale, negative)
.
pub fn precision(&self) -> u8
[src]
Returns the precision, i.e. the count of significant digits in this decimal.
pub const fn scale(&self) -> i16
[src]
Returns the scale, i.e. the count of decimal digits in the fractional part. A positive scale means a negative power of 10.
pub const fn is_sign_negative(&self) -> bool
[src]
Returns true
if the sign bit of the decimal is negative.
pub const fn is_sign_positive(&self) -> bool
[src]
Returns true
if the sign bit of the decimal is positive.
pub const fn is_zero(&self) -> bool
[src]
Checks if self
is zero.
pub const fn abs(&self) -> Decimal
[src]
Computes the absolute value of self
.
pub fn encode<W: Write>(&self, writer: W) -> Result<usize>
[src]
Encodes self
to writer
as binary bytes.
Returns total size on success, which is not larger than MAX_BINARY_SIZE
.
pub fn compact_encode<W: Write>(&self, writer: W) -> Result<usize>
[src]
Encodes self
to writer
as binary bytes.
Returns total size on success, which is not larger than MAX_BINARY_SIZE
.
The only different from Decimal::encode
is it will compact encoded bytes
when self
is zero or small positive integer.
pub fn decode(bytes: &[u8]) -> Decimal
[src]
Decodes a Decimal
from binary bytes.
pub fn trunc(&self, scale: i16) -> Decimal
[src]
Truncate a value to have scale
digits after the decimal point.
We allow negative scale
, implying a truncation before the decimal
point.
pub fn round(&self, scale: i16) -> Decimal
[src]
Round a value to have scale
digits after the decimal point.
We allow negative scale
, implying rounding before the decimal
point.
pub fn round_with_precision(&mut self, precision: u8, scale: i16) -> bool
[src]
Do bounds checking and rounding according to precision
and scale
.
Returns true
if overflows.
pub fn normalize(&self) -> Decimal
[src]
Normalize a Decimal
’s scale toward zero.
pub fn checked_add(&self, other: Decimal) -> Option<Decimal>
[src]
Add two decimals,
returning None
if overflow occurred.
pub fn checked_sub(&self, other: Decimal) -> Option<Decimal>
[src]
Subtract one decimal from another,
returning None
if overflow occurred.
pub fn checked_mul(&self, other: Decimal) -> Option<Decimal>
[src]
Calculate the product of two decimals,
returning None
if overflow occurred.
pub fn checked_div(&self, other: Decimal) -> Option<Decimal>
[src]
Checked decimal division.
Computes self / other
, returning None
if other == 0
or the division results in overflow.
pub fn checked_rem(&self, other: Decimal) -> Option<Decimal>
[src]
Checked decimal remainder.
Computes self % other
, returning None if rhs == 0 or the division results in overflow.
Trait Implementations
impl PartialOrd<&'_ Decimal> for Decimal
[src]
impl PartialOrd<&'_ Decimal> for Decimal
[src]impl PartialOrd<Decimal> for Decimal
[src]
impl PartialOrd<Decimal> for Decimal
[src]impl PartialOrd<Decimal> for &Decimal
[src]
impl PartialOrd<Decimal> for &Decimal
[src]impl StructuralEq for Decimal
[src]
impl StructuralEq for Decimal
[src]Auto Trait Implementations
impl RefUnwindSafe for Decimal
impl RefUnwindSafe for Decimal
impl UnwindSafe for Decimal
impl UnwindSafe for Decimal