SignedNumeric

Struct SignedNumeric 

Source
pub struct SignedNumeric {
    pub value: UnsignedNumeric,
    pub is_negative: bool,
}
Expand description

A SignedNumeric represents a signed 192-bit fixed-point number with 18 decimal places of precision.

This struct extends UnsignedNumeric by adding a bool flag to indicate whether the value is negative, enabling full support for signed decimal arithmetic.

§Internal Representation

  • The magnitude is stored as a UnsignedNumeric, which wraps a [InnerUint] representing a 192-bit unsigned integer scaled by 10¹⁸.
  • The is_negative flag determines the sign of the number.

§Interpretation

The real-world value of a SignedNumeric is:

value = (is_negative ? -1 : 1) × (magnitude / 10^18)

§Examples:

  • value = UnsignedNumeric::from_u192([1_000_000_000_000_000_000, 0, 0]), is_negative = false → 1.0
  • value = UnsignedNumeric::from_u192([5_000_000_000_000_000_000, 0, 0]), is_negative = true → -5.0

This format is useful for financial and scientific applications where both precision and sign are critical, and where floating-point inaccuracies are unacceptable.

Fields§

§value: UnsignedNumeric§is_negative: bool

Implementations§

Source§

impl SignedNumeric

Source

pub fn new(value: i128) -> Self

Source

pub fn negate(&self) -> SignedNumeric

Source

pub fn checked_mul(&self, rhs: &Self) -> Option<SignedNumeric>

Source

pub fn checked_div(&self, rhs: &Self) -> Option<SignedNumeric>

Source

pub fn checked_add(&self, rhs: &Self) -> Option<SignedNumeric>

Source

pub fn checked_sub(&self, rhs: &Self) -> Option<SignedNumeric>

Source

pub fn floor(&self) -> Option<SignedNumeric>

Source

pub fn to_string(&self) -> String

Source§

impl SignedNumeric

Source

pub fn exp(&self) -> Option<UnsignedNumeric>

Calculate the exponential of x, that is, e raised to the power x (where e is the base of the natural system of logarithms, approximately 2.71828). Note that precision can start to get inaccurate for larger numbers (> 20).

Source

pub fn sqrt(&self) -> Option<Self>

Returns the square root of self, returning None if the number is negative.

Trait Implementations§

Source§

impl Add<&SignedNumeric> for &SignedNumeric

Source§

type Output = SignedNumeric

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &SignedNumeric) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<&SignedNumeric> for SignedNumeric

Source§

type Output = SignedNumeric

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<SignedNumeric> for &SignedNumeric

Source§

type Output = SignedNumeric

The resulting type after applying the + operator.
Source§

fn add(self, rhs: SignedNumeric) -> Self::Output

Performs the + operation. Read more
Source§

impl Add for SignedNumeric

Source§

type Output = SignedNumeric

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Clone for SignedNumeric

Source§

fn clone(&self) -> SignedNumeric

Returns a duplicate 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 SignedNumeric

Source§

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

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

impl Div<&SignedNumeric> for &SignedNumeric

Source§

type Output = SignedNumeric

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &SignedNumeric) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<&SignedNumeric> for SignedNumeric

Source§

type Output = SignedNumeric

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &Self) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<SignedNumeric> for &SignedNumeric

Source§

type Output = SignedNumeric

The resulting type after applying the / operator.
Source§

fn div(self, rhs: SignedNumeric) -> Self::Output

Performs the / operation. Read more
Source§

impl Div for SignedNumeric

Source§

type Output = SignedNumeric

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Source§

impl Mul<&SignedNumeric> for &SignedNumeric

Source§

type Output = SignedNumeric

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &SignedNumeric) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<&SignedNumeric> for SignedNumeric

Source§

type Output = SignedNumeric

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Self) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<SignedNumeric> for &SignedNumeric

Source§

type Output = SignedNumeric

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: SignedNumeric) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul for SignedNumeric

Source§

type Output = SignedNumeric

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl PartialEq for SignedNumeric

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sub<&SignedNumeric> for &SignedNumeric

Source§

type Output = SignedNumeric

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &SignedNumeric) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<&SignedNumeric> for SignedNumeric

Source§

type Output = SignedNumeric

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Self) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<SignedNumeric> for &SignedNumeric

Source§

type Output = SignedNumeric

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: SignedNumeric) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub for SignedNumeric

Source§

type Output = SignedNumeric

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl StructuralPartialEq for SignedNumeric

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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<T> ToOwned for T
where T: Clone,

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.