Struct ion_rs::types::Decimal

source ·
pub struct Decimal { /* private fields */ }
Expand description

An arbitrary-precision Decimal type with a distinct representation of negative zero (-0).

Implementations§

source§

impl Decimal

source

pub fn new<I: Into<Coefficient>>(coefficient: I, exponent: i64) -> Decimal

Constructs a new Decimal with the provided components. The value of the decimal is (coefficient * 10^exponent) * (if sign == Sign::Negative { -1 } else { 1 })

source

pub fn scale(&self) -> i64

Returns scale of the Decimal value If zero or positive, a scale indicates the number of digits to the right of the decimal point. If negative, the unscaled value of the number is multiplied by ten to the power of the negation of the scale. For example, a scale of -3 means the unscaled value is multiplied by 1000.

source

pub fn precision(&self) -> u64

Returns the number of digits in the non-scaled integer representation of the decimal.

source

pub fn negative_zero() -> Decimal

Constructs a Decimal with the value -0d0. This is provided as a convenience method because Rust will ignore a unary minus when it is applied to an zero literal (-0).

source

pub fn negative_zero_with_exponent(exponent: i64) -> Decimal

Constructs a Decimal with a coefficient of -0 and the specified exponent. This function is provided as a convenience method because Rust will ignore a unary minus when it is applied to a zero literal (-0).

source

pub fn is_zero(&self) -> bool

Returns true if this Decimal is a zero of any sign or exponent.

source

pub fn is_less_than_zero(&self) -> bool

Returns true if this Decimal’s coefficient has a negative sign AND a magnitude greater than zero. Otherwise, returns false. (Negative zero returns false.)

Trait Implementations§

source§

impl Clone for Decimal

source§

fn clone(&self) -> Decimal

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Decimal

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for Decimal

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<BigDecimal> for Decimal

Make a Decimal from a BigDecimal. This is a lossless operation.

source§

fn from(value: BigDecimal) -> Self

Converts to this type from the input type.
source§

impl From<Decimal> for Value

source§

fn from(decimal_val: Decimal) -> Self

Converts to this type from the input type.
source§

impl From<i16> for Decimal

source§

fn from(value: i16) -> Self

Converts to this type from the input type.
source§

impl From<i32> for Decimal

source§

fn from(value: i32) -> Self

Converts to this type from the input type.
source§

impl From<i64> for Decimal

source§

fn from(value: i64) -> Self

Converts to this type from the input type.
source§

impl From<i8> for Decimal

source§

fn from(value: i8) -> Self

Converts to this type from the input type.
source§

impl From<isize> for Decimal

source§

fn from(value: isize) -> Self

Converts to this type from the input type.
source§

impl From<u16> for Decimal

source§

fn from(value: u16) -> Self

Converts to this type from the input type.
source§

impl From<u32> for Decimal

source§

fn from(value: u32) -> Self

Converts to this type from the input type.
source§

impl From<u64> for Decimal

source§

fn from(value: u64) -> Self

Converts to this type from the input type.
source§

impl From<u8> for Decimal

source§

fn from(value: u8) -> Self

Converts to this type from the input type.
source§

impl From<usize> for Decimal

source§

fn from(value: usize) -> Self

Converts to this type from the input type.
source§

impl Ord for Decimal

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<Decimal> for Decimal

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<Decimal> for Decimal

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl TryFrom<Decimal> for BigDecimal

source§

fn try_from(value: Decimal) -> Result<Self, Self::Error>

Attempts to create a BigDecimal from a Decimal. Returns an Error if the Decimal being converted is a negative zero, which BigDecimal cannot represent. Returns Ok otherwise.

§

type Error = IonError

The type returned in the event of a conversion error.
source§

impl TryFrom<f32> for Decimal

§

type Error = IonError

The type returned in the event of a conversion error.
source§

fn try_from(value: f32) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<f64> for Decimal

source§

fn try_from(value: f64) -> Result<Self, Self::Error>

Attempts to create a Decimal from an f64. Returns an Error if the f64 being converted is a special value, including:

  • Infinity
  • Negative infinity
  • NaN (not-a-number) Otherwise, returns Ok.

Because Decimal can represent negative zero, f64::neg_zero() IS supported.

NOTE: While the resulting decimal will be a very close approximation of the original f64’s value, this is an inherently lossy operation. Floating point values do not encode a precision. When converting an f64 to a Decimal, a precision for the new Decimal must be chosen somewhat arbitrarily. Do NOT rely on the precision of the resulting Decimal. This implementation may change without notice.

§

type Error = IonError

The type returned in the event of a conversion error.
source§

impl Eq for Decimal

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<V> IntoAnnotatedElement for Vwhere V: Into<Value>,

source§

fn with_annotations<I: IntoAnnotations>(self, annotations: I) -> Element

Converts the value into an Element with the specified annotations.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.