Type Alias levana_perpswap_cosmos::number::Number
source · pub type Number = Signed<Decimal256>;
Expand description
A signed number type with high fidelity.
Similar in spirit to cosmwasm_bignumber::Decimal256 - it is a more ergonomic wrapper around cosmwasm-std by making more things public but we also add negative values and other methods as-needed
MANY OF THE METHODS ARE COPY/PASTE FROM cosmwasm_std
the hope is that this is a temporary hack until cosmwasm_math
lands
Aliased Type§
struct Number { /* private fields */ }
Implementations§
source§impl Number
impl Number
sourcepub fn from_ratio_u256<A: Into<Uint256>, B: Into<Uint256>>(
numerator: A,
denominator: B,
) -> Self
pub fn from_ratio_u256<A: Into<Uint256>, B: Into<Uint256>>( numerator: A, denominator: B, ) -> Self
Returns the ratio (nominator / denominator) as a positive Number
sourcepub fn to_u128_with_precision(&self, precision: u32) -> Option<u128>
pub fn to_u128_with_precision(&self, precision: u32) -> Option<u128>
Represent as a u128 encoded with given decimal places
NOTE decimals may be dropped if precision isn’t sufficient to represent all digits completely
sourcepub fn from_fixed_u128(amount: u128, places: u32) -> Self
pub fn from_fixed_u128(amount: u128, places: u32) -> Self
helper to get from native currency to Number e.g. from uusd to UST, as a Decimal
sourcepub fn to_unsigned_key_bytes(&self) -> Option<[u8; 32]>
pub fn to_unsigned_key_bytes(&self) -> Option<[u8; 32]>
Useful for when Number is used as a PrimaryKey and is guaranteed to always be positive
sourcepub fn from_unsigned_key_bytes(bytes: [u8; 32]) -> Self
pub fn from_unsigned_key_bytes(bytes: [u8; 32]) -> Self
Round-tripping with Self::to_unsigned_key_bytes
source§impl Number
impl Number
sourcepub fn checked_mul(self, rhs: Self) -> Result<Self>
pub fn checked_mul(self, rhs: Self) -> Result<Self>
Multiplication that checks for integer overflow
sourcepub fn checked_div(self, rhs: Self) -> Result<Self>
pub fn checked_div(self, rhs: Self) -> Result<Self>
Division that checks for underflow and divide-by-zero.
sourcepub fn approx_eq(self, other: Number) -> Result<bool>
pub fn approx_eq(self, other: Number) -> Result<bool>
equality check with allowance for precision diff
sourcepub fn approx_eq_eps(self, other: Number, eps: Number) -> Result<bool>
pub fn approx_eq_eps(self, other: Number, eps: Number) -> Result<bool>
equality check with allowance for precision diff
sourcepub fn approx_lt_relaxed(self, other: Number) -> Result<bool>
pub fn approx_lt_relaxed(self, other: Number) -> Result<bool>
less-than with allowance for precision diff
sourcepub fn approx_gt_relaxed(self, other: Number) -> Result<bool>
pub fn approx_gt_relaxed(self, other: Number) -> Result<bool>
greater-than with allowance for precision diff
sourcepub fn approx_gt_strict(self, other: Number) -> Result<bool>
pub fn approx_gt_strict(self, other: Number) -> Result<bool>
greater-than with restriction for precision diff