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_negativeflag 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.0value = 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: boolImplementations§
Source§impl SignedNumeric
impl SignedNumeric
pub fn new(value: i128) -> Self
pub fn negate(&self) -> SignedNumeric
pub fn checked_mul(&self, rhs: &Self) -> Option<SignedNumeric>
pub fn checked_div(&self, rhs: &Self) -> Option<SignedNumeric>
pub fn checked_add(&self, rhs: &Self) -> Option<SignedNumeric>
pub fn checked_sub(&self, rhs: &Self) -> Option<SignedNumeric>
pub fn floor(&self) -> Option<SignedNumeric>
pub fn to_string(&self) -> String
Source§impl SignedNumeric
impl SignedNumeric
Sourcepub fn exp(&self) -> Option<UnsignedNumeric>
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).
Trait Implementations§
Source§impl Add<&SignedNumeric> for &SignedNumeric
impl Add<&SignedNumeric> for &SignedNumeric
Source§type Output = SignedNumeric
type Output = SignedNumeric
The resulting type after applying the
+ operator.Source§impl Add<&SignedNumeric> for SignedNumeric
impl Add<&SignedNumeric> for SignedNumeric
Source§impl Add<SignedNumeric> for &SignedNumeric
impl Add<SignedNumeric> for &SignedNumeric
Source§type Output = SignedNumeric
type Output = SignedNumeric
The resulting type after applying the
+ operator.Source§impl Add for SignedNumeric
impl Add for SignedNumeric
Source§impl Clone for SignedNumeric
impl Clone for SignedNumeric
Source§fn clone(&self) -> SignedNumeric
fn clone(&self) -> SignedNumeric
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SignedNumeric
impl Debug for SignedNumeric
Source§impl Div<&SignedNumeric> for &SignedNumeric
impl Div<&SignedNumeric> for &SignedNumeric
Source§type Output = SignedNumeric
type Output = SignedNumeric
The resulting type after applying the
/ operator.Source§impl Div<&SignedNumeric> for SignedNumeric
impl Div<&SignedNumeric> for SignedNumeric
Source§impl Div<SignedNumeric> for &SignedNumeric
impl Div<SignedNumeric> for &SignedNumeric
Source§type Output = SignedNumeric
type Output = SignedNumeric
The resulting type after applying the
/ operator.Source§impl Div for SignedNumeric
impl Div for SignedNumeric
Source§impl Mul<&SignedNumeric> for &SignedNumeric
impl Mul<&SignedNumeric> for &SignedNumeric
Source§type Output = SignedNumeric
type Output = SignedNumeric
The resulting type after applying the
* operator.Source§impl Mul<&SignedNumeric> for SignedNumeric
impl Mul<&SignedNumeric> for SignedNumeric
Source§impl Mul<SignedNumeric> for &SignedNumeric
impl Mul<SignedNumeric> for &SignedNumeric
Source§type Output = SignedNumeric
type Output = SignedNumeric
The resulting type after applying the
* operator.Source§impl Mul for SignedNumeric
impl Mul for SignedNumeric
Source§impl PartialEq for SignedNumeric
impl PartialEq for SignedNumeric
Source§impl Sub<&SignedNumeric> for &SignedNumeric
impl Sub<&SignedNumeric> for &SignedNumeric
Source§type Output = SignedNumeric
type Output = SignedNumeric
The resulting type after applying the
- operator.Source§impl Sub<&SignedNumeric> for SignedNumeric
impl Sub<&SignedNumeric> for SignedNumeric
Source§impl Sub<SignedNumeric> for &SignedNumeric
impl Sub<SignedNumeric> for &SignedNumeric
Source§type Output = SignedNumeric
type Output = SignedNumeric
The resulting type after applying the
- operator.Source§impl Sub for SignedNumeric
impl Sub for SignedNumeric
impl StructuralPartialEq for SignedNumeric
Auto Trait Implementations§
impl Freeze for SignedNumeric
impl RefUnwindSafe for SignedNumeric
impl Send for SignedNumeric
impl Sync for SignedNumeric
impl Unpin for SignedNumeric
impl UnwindSafe for SignedNumeric
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more