pub struct DynamicDecimal {
pub sig: i128,
pub exponent: u8,
}Expand description
Decimal real number with 38 digits of precision and dynamic scale.
This type is primarily meant as a serialized form of Fixed that does not
require parameterization. Any Fixed can be converted into
DynamicDecimal and then converted back into any other Fixed, possibly
with a different precision and scale, without loss of precision (beyond that
inherent in change of scale, if any).
Fields§
§sig: i128The underlying value (significand), multiplied by 10**exponent.
exponent: u8The number of digits of value that follow the decimal point.
Implementations§
Trait Implementations§
Source§impl Clone for DynamicDecimal
impl Clone for DynamicDecimal
Source§fn clone(&self) -> DynamicDecimal
fn clone(&self) -> DynamicDecimal
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DynamicDecimal
impl Debug for DynamicDecimal
Source§impl Default for DynamicDecimal
impl Default for DynamicDecimal
Source§fn default() -> DynamicDecimal
fn default() -> DynamicDecimal
Source§impl Display for DynamicDecimal
impl Display for DynamicDecimal
Source§impl From<DynamicDecimal> for i128
impl From<DynamicDecimal> for i128
Source§fn from(value: DynamicDecimal) -> Self
fn from(value: DynamicDecimal) -> Self
Convert from Fixed to integer, rounding toward zero (the same
semantics as Rust casts from float to integer).
Source§impl From<i128> for DynamicDecimal
impl From<i128> for DynamicDecimal
Source§impl From<i16> for DynamicDecimal
impl From<i16> for DynamicDecimal
Source§impl From<i32> for DynamicDecimal
impl From<i32> for DynamicDecimal
Source§impl From<i64> for DynamicDecimal
impl From<i64> for DynamicDecimal
Source§impl From<i8> for DynamicDecimal
impl From<i8> for DynamicDecimal
Source§impl From<isize> for DynamicDecimal
impl From<isize> for DynamicDecimal
Source§impl From<u16> for DynamicDecimal
impl From<u16> for DynamicDecimal
Source§impl From<u32> for DynamicDecimal
impl From<u32> for DynamicDecimal
Source§impl From<u64> for DynamicDecimal
impl From<u64> for DynamicDecimal
Source§impl From<u8> for DynamicDecimal
impl From<u8> for DynamicDecimal
Source§impl From<usize> for DynamicDecimal
impl From<usize> for DynamicDecimal
Source§impl FromStr for DynamicDecimal
impl FromStr for DynamicDecimal
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Parses s as DynamicDecimal.
This accepts the same forms as f64::from_str, except that it rejects
infinities and NaNs (which Fixed does not support), as well as
out-of-range values. Rounds overprecise values to the nearest
representable value, rounding halfway values to even.
Source§type Err = ParseDecimalError
type Err = ParseDecimalError
Source§impl Ord for DynamicDecimal
impl Ord for DynamicDecimal
Source§impl PartialEq for DynamicDecimal
impl PartialEq for DynamicDecimal
Source§impl PartialOrd for DynamicDecimal
impl PartialOrd for DynamicDecimal
Source§impl<const P: usize, const S: usize> TryFrom<DynamicDecimal> for Fixed<P, S>
impl<const P: usize, const S: usize> TryFrom<DynamicDecimal> for Fixed<P, S>
Source§fn try_from(value: DynamicDecimal) -> Result<Self, Self::Error>
fn try_from(value: DynamicDecimal) -> Result<Self, Self::Error>
Deserializes DynamicDecimal into Fixed. If successful, returns the
original value from before serialization. If S < value.exponent, then
some trailing decimals are lost, by rounding toward zero. Returns an
error` if the value is out of range for this type.
Source§type Error = OutOfRange
type Error = OutOfRange
Source§impl TryFrom<DynamicDecimal> for i16
impl TryFrom<DynamicDecimal> for i16
Source§fn try_from(value: DynamicDecimal) -> Result<Self, Self::Error>
fn try_from(value: DynamicDecimal) -> Result<Self, Self::Error>
Convert from Fixed to integer, rounding toward zero (the same
semantics as Rust casts from float to integer).
Source§type Error = OutOfRange
type Error = OutOfRange
Source§impl TryFrom<DynamicDecimal> for i32
impl TryFrom<DynamicDecimal> for i32
Source§fn try_from(value: DynamicDecimal) -> Result<Self, Self::Error>
fn try_from(value: DynamicDecimal) -> Result<Self, Self::Error>
Convert from Fixed to integer, rounding toward zero (the same
semantics as Rust casts from float to integer).
Source§type Error = OutOfRange
type Error = OutOfRange
Source§impl TryFrom<DynamicDecimal> for i64
impl TryFrom<DynamicDecimal> for i64
Source§fn try_from(value: DynamicDecimal) -> Result<Self, Self::Error>
fn try_from(value: DynamicDecimal) -> Result<Self, Self::Error>
Convert from Fixed to integer, rounding toward zero (the same
semantics as Rust casts from float to integer).
Source§type Error = OutOfRange
type Error = OutOfRange
Source§impl TryFrom<DynamicDecimal> for i8
impl TryFrom<DynamicDecimal> for i8
Source§fn try_from(value: DynamicDecimal) -> Result<Self, Self::Error>
fn try_from(value: DynamicDecimal) -> Result<Self, Self::Error>
Convert from Fixed to integer, rounding toward zero (the same
semantics as Rust casts from float to integer).
Source§type Error = OutOfRange
type Error = OutOfRange
Source§impl TryFrom<DynamicDecimal> for isize
impl TryFrom<DynamicDecimal> for isize
Source§fn try_from(value: DynamicDecimal) -> Result<Self, Self::Error>
fn try_from(value: DynamicDecimal) -> Result<Self, Self::Error>
Convert from Fixed to integer, rounding toward zero (the same
semantics as Rust casts from float to integer).
Source§type Error = OutOfRange
type Error = OutOfRange
Source§impl TryFrom<DynamicDecimal> for u128
impl TryFrom<DynamicDecimal> for u128
Source§fn try_from(value: DynamicDecimal) -> Result<Self, Self::Error>
fn try_from(value: DynamicDecimal) -> Result<Self, Self::Error>
Convert from Fixed to integer, rounding toward zero (the same
semantics as Rust casts from float to integer).
Because this rounds toward zero, negative values greater than -1 will convert to 0 instead of an out-of-range error.
Source§type Error = OutOfRange
type Error = OutOfRange
Source§impl TryFrom<DynamicDecimal> for u16
impl TryFrom<DynamicDecimal> for u16
Source§fn try_from(value: DynamicDecimal) -> Result<Self, Self::Error>
fn try_from(value: DynamicDecimal) -> Result<Self, Self::Error>
Convert from Fixed to integer, rounding toward zero (the same
semantics as Rust casts from float to integer).
Because this rounds toward zero, negative values greater than -1 will convert to 0 instead of an out-of-range error.
Source§type Error = OutOfRange
type Error = OutOfRange
Source§impl TryFrom<DynamicDecimal> for u32
impl TryFrom<DynamicDecimal> for u32
Source§fn try_from(value: DynamicDecimal) -> Result<Self, Self::Error>
fn try_from(value: DynamicDecimal) -> Result<Self, Self::Error>
Convert from Fixed to integer, rounding toward zero (the same
semantics as Rust casts from float to integer).
Because this rounds toward zero, negative values greater than -1 will convert to 0 instead of an out-of-range error.
Source§type Error = OutOfRange
type Error = OutOfRange
Source§impl TryFrom<DynamicDecimal> for u64
impl TryFrom<DynamicDecimal> for u64
Source§fn try_from(value: DynamicDecimal) -> Result<Self, Self::Error>
fn try_from(value: DynamicDecimal) -> Result<Self, Self::Error>
Convert from Fixed to integer, rounding toward zero (the same
semantics as Rust casts from float to integer).
Because this rounds toward zero, negative values greater than -1 will convert to 0 instead of an out-of-range error.
Source§type Error = OutOfRange
type Error = OutOfRange
Source§impl TryFrom<DynamicDecimal> for u8
impl TryFrom<DynamicDecimal> for u8
Source§fn try_from(value: DynamicDecimal) -> Result<Self, Self::Error>
fn try_from(value: DynamicDecimal) -> Result<Self, Self::Error>
Convert from Fixed to integer, rounding toward zero (the same
semantics as Rust casts from float to integer).
Because this rounds toward zero, negative values greater than -1 will convert to 0 instead of an out-of-range error.
Source§type Error = OutOfRange
type Error = OutOfRange
Source§impl TryFrom<DynamicDecimal> for usize
impl TryFrom<DynamicDecimal> for usize
Source§fn try_from(value: DynamicDecimal) -> Result<Self, Self::Error>
fn try_from(value: DynamicDecimal) -> Result<Self, Self::Error>
Convert from Fixed to integer, rounding toward zero (the same
semantics as Rust casts from float to integer).
Because this rounds toward zero, negative values greater than -1 will convert to 0 instead of an out-of-range error.