diff --git a/CHANGELOG.md b/CHANGELOG.md index 42f5bfee31..27ec8119e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/std/src/math/decimal.rs b/packages/std/src/math/decimal.rs index 163271bedd..a97bf29ead 100644 --- a/packages/std/src/math/decimal.rs +++ b/packages/std/src/math/decimal.rs @@ -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. diff --git a/packages/std/src/math/decimal256.rs b/packages/std/src/math/decimal256.rs index cd7aaa62b7..eed988c18d 100644 --- a/packages/std/src/math/decimal256.rs +++ b/packages/std/src/math/decimal256.rs @@ -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. diff --git a/packages/std/src/math/uint128.rs b/packages/std/src/math/uint128.rs index fddd98bbd4..150166810a 100644 --- a/packages/std/src/math/uint128.rs +++ b/packages/std/src/math/uint128.rs @@ -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). /// diff --git a/packages/std/src/math/uint256.rs b/packages/std/src/math/uint256.rs index 1e4349d16d..e1c14ac94a 100644 --- a/packages/std/src/math/uint256.rs +++ b/packages/std/src/math/uint256.rs @@ -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`]. diff --git a/packages/std/src/math/uint512.rs b/packages/std/src/math/uint512.rs index 18c6ce527e..2a66189b44 100644 --- a/packages/std/src/math/uint512.rs +++ b/packages/std/src/math/uint512.rs @@ -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`. diff --git a/packages/std/src/math/uint64.rs b/packages/std/src/math/uint64.rs index 7267552a72..3b1df29d17 100644 --- a/packages/std/src/math/uint64.rs +++ b/packages/std/src/math/uint64.rs @@ -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). ///