Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions packages/std/src/math/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ impl Decimal {
}

/// Convert x% into Decimal
pub fn percent(x: u64) -> Self {
Decimal(((x as u128) * 10_000_000_000_000_000).into())
pub const fn percent(x: u64) -> Self {
Decimal(Uint128::new((x as u128) * 10_000_000_000_000_000))
}

/// Convert permille (x/1000) into Decimal
pub fn permille(x: u64) -> Self {
Decimal(((x as u128) * 1_000_000_000_000_000).into())
pub const fn permille(x: u64) -> Self {
Decimal(Uint128::new((x as u128) * 1_000_000_000_000_000))
}

/// Creates a decimal from a number of atomic units and the number
Expand Down Expand Up @@ -117,7 +117,7 @@ impl Decimal {
)
}

pub fn is_zero(&self) -> bool {
pub const fn is_zero(&self) -> bool {
self.0.is_zero()
}

Expand All @@ -139,15 +139,15 @@ impl Decimal {
/// assert_eq!(b.decimal_places(), 18);
/// assert_eq!(b.atomics(), Uint128::new(1));
/// ```
pub fn atomics(&self) -> Uint128 {
pub const fn atomics(&self) -> Uint128 {
self.0
}

/// The number of decimal places. This is a constant value for now
/// but this could potentially change as the type evolves.
///
/// See also [`Decimal::atomics()`].
pub fn decimal_places(&self) -> u32 {
pub const fn decimal_places(&self) -> u32 {
Self::DECIMAL_PLACES as u32
}

Expand Down
18 changes: 9 additions & 9 deletions packages/std/src/math/uint128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Uint128 {
self.0.to_le_bytes()
}

pub fn is_zero(&self) -> bool {
pub const fn is_zero(&self) -> bool {
self.0 == 0
}

Expand Down Expand Up @@ -114,35 +114,35 @@ impl Uint128 {
.ok_or_else(|| DivideByZeroError::new(self))
}

pub fn wrapping_add(self, other: Self) -> Self {
pub const fn wrapping_add(self, other: Self) -> Self {
Self(self.0.wrapping_add(other.0))
}

pub fn wrapping_sub(self, other: Self) -> Self {
pub const fn wrapping_sub(self, other: Self) -> Self {
Self(self.0.wrapping_sub(other.0))
}

pub fn wrapping_mul(self, other: Self) -> Self {
pub const fn wrapping_mul(self, other: Self) -> Self {
Self(self.0.wrapping_mul(other.0))
}

pub fn wrapping_pow(self, other: u32) -> Self {
pub const fn wrapping_pow(self, other: u32) -> Self {
Self(self.0.wrapping_pow(other))
}

pub fn saturating_add(self, other: Self) -> Self {
pub const fn saturating_add(self, other: Self) -> Self {
Self(self.0.saturating_add(other.0))
}

pub fn saturating_sub(self, other: Self) -> Self {
pub const fn saturating_sub(self, other: Self) -> Self {
Self(self.0.saturating_sub(other.0))
}

pub fn saturating_mul(self, other: Self) -> Self {
pub const fn saturating_mul(self, other: Self) -> Self {
Self(self.0.saturating_mul(other.0))
}

pub fn saturating_pow(self, other: u32) -> Self {
pub const fn saturating_pow(self, other: u32) -> Self {
Self(self.0.saturating_pow(other))
}
}
Expand Down
18 changes: 9 additions & 9 deletions packages/std/src/math/uint64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Uint64 {
self.0.to_le_bytes()
}

pub fn is_zero(&self) -> bool {
pub const fn is_zero(&self) -> bool {
self.0 == 0
}

Expand Down Expand Up @@ -103,35 +103,35 @@ impl Uint64 {
.ok_or_else(|| DivideByZeroError::new(self))
}

pub fn wrapping_add(self, other: Self) -> Self {
pub const fn wrapping_add(self, other: Self) -> Self {
Self(self.0.wrapping_add(other.0))
}

pub fn wrapping_sub(self, other: Self) -> Self {
pub const fn wrapping_sub(self, other: Self) -> Self {
Self(self.0.wrapping_sub(other.0))
}

pub fn wrapping_mul(self, other: Self) -> Self {
pub const fn wrapping_mul(self, other: Self) -> Self {
Self(self.0.wrapping_mul(other.0))
}

pub fn wrapping_pow(self, other: u32) -> Self {
pub const fn wrapping_pow(self, other: u32) -> Self {
Self(self.0.wrapping_pow(other))
}

pub fn saturating_add(self, other: Self) -> Self {
pub const fn saturating_add(self, other: Self) -> Self {
Self(self.0.saturating_add(other.0))
}

pub fn saturating_sub(self, other: Self) -> Self {
pub const fn saturating_sub(self, other: Self) -> Self {
Self(self.0.saturating_sub(other.0))
}

pub fn saturating_mul(self, other: Self) -> Self {
pub const fn saturating_mul(self, other: Self) -> Self {
Self(self.0.saturating_mul(other.0))
}

pub fn saturating_pow(self, other: u32) -> Self {
pub const fn saturating_pow(self, other: u32) -> Self {
Self(self.0.saturating_pow(other))
}
}
Expand Down