Skip to content

Commit

Permalink
Merge pull request #1366 from CosmWasm/1186-implement-min-const
Browse files Browse the repository at this point in the history
`Uint`/`Decimal`: Implement const MIN
  • Loading branch information
ueco-jb authored Jul 14, 2022
2 parents 4b09ecd + dd24f20 commit 9bf920b
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to
- cosmwasm-std: Implement `ceil`/`floor` for `Decimal`/`Decimal256`.
- cosmwasm-std: Implement `saturating_add`/`sub`/`mul` for
`Decimal`/`Decimal256`.
- cosmwasm-std: Implement `MIN` const value for all `Uint` and `Decimal` types

[#1334]: https://github.com/CosmWasm/cosmwasm/pull/1334

Expand Down
2 changes: 2 additions & 0 deletions packages/std/src/math/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ impl Decimal {
pub const DECIMAL_PLACES: u32 = 18; // This needs to be an even number.
/// The largest value that can be represented by this decimal type.
pub const MAX: Self = Self(Uint128::MAX);
/// The smallest value that can be represented by this decimal type.
pub const MIN: Self = Self(Uint128::MIN);

/// Creates a Decimal(value)
/// This is equivalent to `Decimal::from_atomics(value, 18)` but usable in a const context.
Expand Down
2 changes: 2 additions & 0 deletions packages/std/src/math/decimal256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ impl Decimal256 {
pub const DECIMAL_PLACES: u32 = 18;
/// The largest value that can be represented by this decimal type.
pub const MAX: Self = Self(Uint256::MAX);
/// The smallest value that can be represented by this decimal type.
pub const MIN: Self = Self(Uint256::MIN);

/// Creates a Decimal256 from Uint256
/// This is equivalent to `Decimal256::from_atomics(value, 18)` but usable in a const context.
Expand Down
1 change: 1 addition & 0 deletions packages/std/src/math/uint128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct Uint128(#[schemars(with = "String")] u128);

impl Uint128 {
pub const MAX: Self = Self(u128::MAX);
pub const MIN: Self = Self(u128::MIN);

/// Creates a Uint128(value).
///
Expand Down
1 change: 1 addition & 0 deletions packages/std/src/math/uint256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub struct Uint256(#[schemars(with = "String")] U256);

impl Uint256 {
pub const MAX: Uint256 = Uint256(U256::MAX);
pub const MIN: Uint256 = Uint256(U256::zero());

/// Creates a Uint256(value) from a big endian representation. It's just an alias for
/// [`Uint256::from_be_bytes`].
Expand Down
1 change: 1 addition & 0 deletions packages/std/src/math/uint512.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub struct Uint512(#[schemars(with = "String")] U512);

impl Uint512 {
pub const MAX: Uint512 = Uint512(U512::MAX);
pub const MIN: Uint512 = Uint512(U512::zero());

/// Creates a Uint512(value) from a big endian representation. It's just an alias for
/// `from_big_endian`.
Expand Down
1 change: 1 addition & 0 deletions packages/std/src/math/uint64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub struct Uint64(#[schemars(with = "String")] u64);

impl Uint64 {
pub const MAX: Self = Self(u64::MAX);
pub const MIN: Self = Self(u64::MIN);

/// Creates a Uint64(value).
///
Expand Down

0 comments on commit 9bf920b

Please sign in to comment.