From 460e2636a70429d06eed1c49c810af3852b55550 Mon Sep 17 00:00:00 2001 From: SwayStar123 Date: Wed, 4 Dec 2024 14:42:24 +0530 Subject: [PATCH 1/7] init --- libs/src/signed_integers/i128.sw | 18 +++++++++++++ libs/src/signed_integers/i16.sw | 18 +++++++++++++ libs/src/signed_integers/i256.sw | 18 +++++++++++++ libs/src/signed_integers/i32.sw | 18 +++++++++++++ libs/src/signed_integers/i64.sw | 18 +++++++++++++ libs/src/signed_integers/i8.sw | 18 +++++++++++++ .../signed_integers/signed_i128/src/main.sw | 25 ++++++++++++++++++ .../signed_integers/signed_i16/src/main.sw | 26 +++++++++++++++++++ .../signed_integers/signed_i256/src/main.sw | 25 ++++++++++++++++++ .../signed_integers/signed_i32/src/main.sw | 25 ++++++++++++++++++ .../signed_integers/signed_i64/src/main.sw | 25 ++++++++++++++++++ .../src/signed_integers/signed_i8/src/main.sw | 26 +++++++++++++++++++ 12 files changed, 260 insertions(+) diff --git a/libs/src/signed_integers/i128.sw b/libs/src/signed_integers/i128.sw index fddcfbe3..727ef7e6 100644 --- a/libs/src/signed_integers/i128.sw +++ b/libs/src/signed_integers/i128.sw @@ -57,6 +57,24 @@ impl core::ops::Ord for I128 { impl core::ops::OrdEq for I128 {} +impl core::ops::TotalOrd for I128 { + fn min(self, other: Self) -> Self { + if self.underlying < other.underlying { + self + } else { + other + } + } + + fn max(self, other: Self) -> Self { + if self.underlying > other.underlying { + self + } else { + other + } + } +} + impl I128 { /// The size of this type in bits. /// diff --git a/libs/src/signed_integers/i16.sw b/libs/src/signed_integers/i16.sw index b3da7430..2d7a2e05 100644 --- a/libs/src/signed_integers/i16.sw +++ b/libs/src/signed_integers/i16.sw @@ -56,6 +56,24 @@ impl core::ops::Ord for I16 { impl core::ops::OrdEq for I16 {} +impl core::ops::TotalOrd for I16 { + fn min(self, other: Self) -> Self { + if self.underlying < other.underlying { + self + } else { + other + } + } + + fn max(self, other: Self) -> Self { + if self.underlying > other.underlying { + self + } else { + other + } + } +} + impl I16 { /// The size of this type in bits. /// diff --git a/libs/src/signed_integers/i256.sw b/libs/src/signed_integers/i256.sw index 92d35bbc..81fb7648 100644 --- a/libs/src/signed_integers/i256.sw +++ b/libs/src/signed_integers/i256.sw @@ -59,6 +59,24 @@ impl core::ops::Ord for I256 { impl core::ops::OrdEq for I256 {} +impl core::ops::TotalOrd for I256 { + fn min(self, other: Self) -> Self { + if self.underlying < other.underlying { + self + } else { + other + } + } + + fn max(self, other: Self) -> Self { + if self.underlying > other.underlying { + self + } else { + other + } + } +} + impl I256 { /// The size of this type in bits. /// diff --git a/libs/src/signed_integers/i32.sw b/libs/src/signed_integers/i32.sw index 1e94e8ee..b3a1301c 100644 --- a/libs/src/signed_integers/i32.sw +++ b/libs/src/signed_integers/i32.sw @@ -56,6 +56,24 @@ impl core::ops::Ord for I32 { impl core::ops::OrdEq for I32 {} +impl core::ops::TotalOrd for I32 { + fn min(self, other: Self) -> Self { + if self.underlying < other.underlying { + self + } else { + other + } + } + + fn max(self, other: Self) -> Self { + if self.underlying > other.underlying { + self + } else { + other + } + } +} + impl I32 { /// The size of this type in bits. /// diff --git a/libs/src/signed_integers/i64.sw b/libs/src/signed_integers/i64.sw index 3b8c24c4..2d53aae6 100644 --- a/libs/src/signed_integers/i64.sw +++ b/libs/src/signed_integers/i64.sw @@ -56,6 +56,24 @@ impl core::ops::Ord for I64 { impl core::ops::OrdEq for I64 {} +impl core::ops::TotalOrd for I64 { + fn min(self, other: Self) -> Self { + if self.underlying < other.underlying { + self + } else { + other + } + } + + fn max(self, other: Self) -> Self { + if self.underlying > other.underlying { + self + } else { + other + } + } +} + impl I64 { /// The size of this type in bits. /// diff --git a/libs/src/signed_integers/i8.sw b/libs/src/signed_integers/i8.sw index 37b9938a..b86f56b5 100644 --- a/libs/src/signed_integers/i8.sw +++ b/libs/src/signed_integers/i8.sw @@ -56,6 +56,24 @@ impl core::ops::Ord for I8 { impl core::ops::OrdEq for I8 {} +impl core::ops::TotalOrd for I8 { + fn min(self, other: Self) -> Self { + if self.underlying < other.underlying { + self + } else { + other + } + } + + fn max(self, other: Self) -> Self { + if self.underlying > other.underlying { + self + } else { + other + } + } +} + impl I8 { /// The size of this type in bits. /// diff --git a/tests/src/signed_integers/signed_i128/src/main.sw b/tests/src/signed_integers/signed_i128/src/main.sw index 681271b0..1f96cf05 100644 --- a/tests/src/signed_integers/signed_i128/src/main.sw +++ b/tests/src/signed_integers/signed_i128/src/main.sw @@ -167,5 +167,30 @@ fn main() -> bool { let U128_overflow_try_into: Option = negative.try_into(); assert(U128_overflow_try_into.is_none()); + // TotalOrd tests + assert(zero.min(one) == zero); + assert(zero.max(one) == one); + assert(one.min(zero) == zero); + assert(one.max(zero) == one); + + assert(max_1.min(one) == one); + assert(max_1.max(one) == max_1); + assert(one.min(max_1) == one); + assert(one.max(max_1) == max_1); + + assert(min_1.min(one) == min_1); + assert(min_1.max(one) == one); + assert(one.min(min_1) == min_1); + assert(one.max(min_1) == one); + + assert(max_1.min(min_1) == min_1); + assert(max_1.max(min_1) == max_1); + assert(min_1.min(max_1) == min_1); + assert(min_1.max(max_1) == max_1); + + assert(neg_one_1.min(one) == neg_one_1); + assert(neg_one_1.max(one) == one); + assert(one.min(neg_one_1) == neg_one_1); + true } diff --git a/tests/src/signed_integers/signed_i16/src/main.sw b/tests/src/signed_integers/signed_i16/src/main.sw index 1f56176c..a50a3ff0 100644 --- a/tests/src/signed_integers/signed_i16/src/main.sw +++ b/tests/src/signed_integers/signed_i16/src/main.sw @@ -155,5 +155,31 @@ fn main() -> bool { let u16_overflow_try_into: Option = negative.try_into(); assert(u16_overflow_try_into.is_none()); + // TotalOrd tests + assert(zero.min(one) == zero); + assert(zero.max(one) == one); + assert(one.min(zero) == zero); + assert(one.max(zero) == one); + + assert(max_1.min(one) == one); + assert(max_1.max(one) == max_1); + assert(one.min(max_1) == one); + assert(one.max(max_1) == max_1); + + assert(min_1.min(one) == min_1); + assert(min_1.max(one) == one); + assert(one.min(min_1) == min_1); + assert(one.max(min_1) == one); + + assert(max_1.min(min_1) == min_1); + assert(max_1.max(min_1) == max_1); + assert(min_1.min(max_1) == min_1); + assert(min_1.max(max_1) == max_1); + + assert(neg_one_1.min(one) == neg_one_1); + assert(neg_one_1.max(one) == one); + assert(one.min(neg_one_1) == neg_one_1); + assert(one.max(neg_one_1) == one); + true } diff --git a/tests/src/signed_integers/signed_i256/src/main.sw b/tests/src/signed_integers/signed_i256/src/main.sw index 1b6cf600..5de73526 100644 --- a/tests/src/signed_integers/signed_i256/src/main.sw +++ b/tests/src/signed_integers/signed_i256/src/main.sw @@ -200,5 +200,30 @@ fn main() -> bool { let u256_overflow_try_into: Option = negative.try_into(); assert(u256_overflow_try_into.is_none()); + // TotalOrd tests + assert(zero.min(one) == zero); + assert(zero.max(one) == one); + assert(one.min(zero) == zero); + assert(one.max(zero) == one); + + assert(max_1.min(one) == one); + assert(max_1.max(one) == max_1); + assert(one.min(max_1) == one); + assert(one.max(max_1) == max_1); + + assert(min_1.min(one) == min_1); + assert(min_1.max(one) == one); + assert(one.min(min_1) == min_1); + assert(one.max(min_1) == one); + + assert(max_1.min(min_1) == min_1); + assert(max_1.max(min_1) == max_1); + assert(min_1.min(max_1) == min_1); + assert(min_1.max(max_1) == max_1); + + assert(neg_one_1.min(one) == neg_one_1); + assert(neg_one_1.max(one) == one); + assert(one.min(neg_one_1) == neg_one_1); + true } diff --git a/tests/src/signed_integers/signed_i32/src/main.sw b/tests/src/signed_integers/signed_i32/src/main.sw index ead519ba..bd55869f 100644 --- a/tests/src/signed_integers/signed_i32/src/main.sw +++ b/tests/src/signed_integers/signed_i32/src/main.sw @@ -155,5 +155,30 @@ fn main() -> bool { let u32_overflow_try_into: Option = negative.try_into(); assert(u32_overflow_try_into.is_none()); + // TotalOrd tests + assert(zero.min(one) == zero); + assert(zero.max(one) == one); + assert(one.min(zero) == zero); + assert(one.max(zero) == one); + + assert(max_1.min(one) == one); + assert(max_1.max(one) == max_1); + assert(one.min(max_1) == one); + assert(one.max(max_1) == max_1); + + assert(min_1.min(one) == min_1); + assert(min_1.max(one) == one); + assert(one.min(min_1) == min_1); + assert(one.max(min_1) == one); + + assert(max_1.min(min_1) == min_1); + assert(max_1.max(min_1) == max_1); + assert(min_1.min(max_1) == min_1); + assert(min_1.max(max_1) == max_1); + + assert(neg_one_1.min(one) == neg_one_1); + assert(neg_one_1.max(one) == one); + assert(one.min(neg_one_1) == neg_one_1); + true } diff --git a/tests/src/signed_integers/signed_i64/src/main.sw b/tests/src/signed_integers/signed_i64/src/main.sw index f6656df3..1d7a9881 100644 --- a/tests/src/signed_integers/signed_i64/src/main.sw +++ b/tests/src/signed_integers/signed_i64/src/main.sw @@ -154,5 +154,30 @@ fn main() -> bool { let u64_overflow_try_into: Option = negative.try_into(); assert(u64_overflow_try_into.is_none()); + // TotalOrd tests + assert(zero.min(one) == zero); + assert(zero.max(one) == one); + assert(one.min(zero) == zero); + assert(one.max(zero) == one); + + assert(max_1.min(one) == one); + assert(max_1.max(one) == max_1); + assert(one.min(max_1) == one); + assert(one.max(max_1) == max_1); + + assert(min_1.min(one) == min_1); + assert(min_1.max(one) == one); + assert(one.min(min_1) == min_1); + assert(one.max(min_1) == one); + + assert(max_1.min(min_1) == min_1); + assert(max_1.max(min_1) == max_1); + assert(min_1.min(max_1) == min_1); + assert(min_1.max(max_1) == max_1); + + assert(neg_one_1.min(one) == neg_one_1); + assert(neg_one_1.max(one) == one); + assert(one.min(neg_one_1) == neg_one_1); + true } diff --git a/tests/src/signed_integers/signed_i8/src/main.sw b/tests/src/signed_integers/signed_i8/src/main.sw index 08586d44..31f97b8a 100644 --- a/tests/src/signed_integers/signed_i8/src/main.sw +++ b/tests/src/signed_integers/signed_i8/src/main.sw @@ -154,5 +154,31 @@ fn main() -> bool { let u8_overflow_try_into: Option = negative.try_into(); assert(u8_overflow_try_into.is_none()); + // TotalOrd tests + assert(zero.min(one) == zero); + assert(zero.max(one) == one); + assert(one.min(zero) == zero); + assert(one.max(zero) == one); + + assert(max_1.min(one) == one); + assert(max_1.max(one) == max_1); + assert(one.min(max_1) == one); + assert(one.max(max_1) == max_1); + + assert(min_1.min(one) == min_1); + assert(min_1.max(one) == one); + assert(one.min(min_1) == min_1); + assert(one.max(min_1) == one); + + assert(max_1.min(min_1) == min_1); + assert(max_1.max(min_1) == max_1); + assert(min_1.min(max_1) == min_1); + assert(min_1.max(max_1) == max_1); + + assert(neg_one_1.min(one) == neg_one_1); + assert(neg_one_1.max(one) == one); + assert(one.min(neg_one_1) == neg_one_1); + assert(one.max(neg_one_1) == one); + true } From 011ffa0bdd4a6b5d136e6b3cb344ac5f36347885 Mon Sep 17 00:00:00 2001 From: SwayStar123 Date: Wed, 4 Dec 2024 14:49:09 +0530 Subject: [PATCH 2/7] update forc version --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4db7ac16..318290f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ env: CARGO_TERM_COLOR: always REGISTRY: ghcr.io RUST_VERSION: 1.80.1 - FORC_VERSION: 0.66.2 + FORC_VERSION: 0.66.5 CORE_VERSION: 0.40.0 jobs: From d47a48409cf5c287f9b61c50ecbad7ce53e2ca61 Mon Sep 17 00:00:00 2001 From: SwayStar123 Date: Wed, 4 Dec 2024 16:16:17 +0530 Subject: [PATCH 3/7] remove old min and max and add MIN and MAX --- CHANGELOG.md | 1 + libs/Forc.lock | 4 +- libs/src/signed_integers/i8.sw | 68 +++++++++++++++------------------- 3 files changed, 33 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef19ff4f..9cbab5d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ Description of the upcoming release here. ### Added - [#309](https://github.com/FuelLabs/sway-libs/pull/309) Adds fallback function test cases to the Reentrancy Guard Library. +- [#312](https://github.com/FuelLabs/sway-libs/pull/312) Implements `TotalOrd` trait for `I8`, `I16`, `I32`, `I64`, `I128`, and `I256`. ### Changed diff --git a/libs/Forc.lock b/libs/Forc.lock index 7ac14885..27725a1b 100644 --- a/libs/Forc.lock +++ b/libs/Forc.lock @@ -1,6 +1,6 @@ [[package]] name = "core" -source = "path+from-root-7053AAA90CC5E690" +source = "path+from-root-6A8836696D55BC6E" [[package]] name = "standards" @@ -9,7 +9,7 @@ dependencies = ["std"] [[package]] name = "std" -source = "git+https://github.com/fuellabs/sway?tag=v0.66.2#31486c0b47669612acb7c64d66ecb50aea281282" +source = "git+https://github.com/fuellabs/sway?tag=v0.66.5#94a066652468b4afa3bd396dacef482ed590976b" dependencies = ["core"] [[package]] diff --git a/libs/src/signed_integers/i8.sw b/libs/src/signed_integers/i8.sw index b86f56b5..8371efbc 100644 --- a/libs/src/signed_integers/i8.sw +++ b/libs/src/signed_integers/i8.sw @@ -75,11 +75,7 @@ impl core::ops::TotalOrd for I8 { } impl I8 { - /// The size of this type in bits. - /// - /// # Returns - /// - /// * [u64] - The number of bits. + /// The smallest value that can be represented by this integer type. /// /// # Examples /// @@ -87,19 +83,15 @@ impl I8 { /// use sway_libs::signed_integers::i8::I8; /// /// fn foo() { - /// let bits = I8::bits(); - /// assert(bits == 8); + /// let i8 = I8::MIN; + /// assert(i8.underlying() == u8::min()); /// } /// ``` - pub fn bits() -> u64 { - 8 - } + const MIN: Self = Self { + underlying: u8::min(), + }; - /// Helper function to get a signed `I8` from an underlying `u8`. - /// - /// # Arguments - /// - /// * `underlying`: [u8] - The `u8` that will represent the `I8`. + /// The largest value that can be represented by this integer type. /// /// # Returns /// @@ -111,20 +103,19 @@ impl I8 { /// use sway_libs::signed_integers::i8::I8; /// /// fn foo() { - /// let underlying = 1u8; - /// let i8 = I8::from_uint(underlying); - /// assert(i8.underlying() == underlying); + /// let i8 = I8::MAX; + /// assert(i8.underlying() == u8::max()); /// } /// ``` - pub fn from_uint(underlying: u8) -> Self { - Self { underlying } - } + const MAX: Self = Self { + underlying: u8::max(), + }; - /// The largest value that can be represented by this integer type. + /// The size of this type in bits. /// /// # Returns /// - /// * [I8] - The newly created `I8` struct. + /// * [u64] - The number of bits. /// /// # Examples /// @@ -132,17 +123,19 @@ impl I8 { /// use sway_libs::signed_integers::i8::I8; /// /// fn foo() { - /// let i8 = I8::max(); - /// assert(i8.underlying() == u8::max()); + /// let bits = I8::bits(); + /// assert(bits == 8); /// } /// ``` - pub fn max() -> Self { - Self { - underlying: u8::max(), - } + pub fn bits() -> u64 { + 8 } - /// The smallest value that can be represented by this integer type. + /// Helper function to get a signed `I8` from an underlying `u8`. + /// + /// # Arguments + /// + /// * `underlying`: [u8] - The `u8` that will represent the `I8`. /// /// # Returns /// @@ -154,14 +147,13 @@ impl I8 { /// use sway_libs::signed_integers::i8::I8; /// /// fn foo() { - /// let i8 = I8::new(); - /// assert(i8.underlying() == u8::min()); + /// let underlying = 1u8; + /// let i8 = I8::from_uint(underlying); + /// assert(i8.underlying() == underlying); /// } /// ``` - pub fn min() -> Self { - Self { - underlying: u8::min(), - } + pub fn from_uint(underlying: u8) -> Self { + Self { underlying } } /// Helper function to get a negative value of an unsigned number. @@ -401,8 +393,8 @@ impl core::ops::Subtract for I8 { impl WrappingNeg for I8 { fn wrapping_neg(self) -> Self { - if self == self::min() { - return self::min() + if self == Self::MIN { + return Self::MIN } self * Self::neg_try_from(1u8).unwrap() } From 7af9b09e96c1b0f20fdef559e16a5518b721683d Mon Sep 17 00:00:00 2001 From: SwayStar123 Date: Mon, 9 Dec 2024 15:17:59 +0530 Subject: [PATCH 4/7] use temp fix --- libs/src/signed_integers/i128.sw | 80 +++++++++++++++----------------- libs/src/signed_integers/i16.sw | 78 +++++++++++++++---------------- libs/src/signed_integers/i256.sw | 78 +++++++++++++++---------------- libs/src/signed_integers/i32.sw | 78 +++++++++++++++---------------- libs/src/signed_integers/i64.sw | 78 +++++++++++++++---------------- libs/src/signed_integers/i8.sw | 8 +++- 6 files changed, 191 insertions(+), 209 deletions(-) diff --git a/libs/src/signed_integers/i128.sw b/libs/src/signed_integers/i128.sw index 727ef7e6..e3ba9be5 100644 --- a/libs/src/signed_integers/i128.sw +++ b/libs/src/signed_integers/i128.sw @@ -76,31 +76,23 @@ impl core::ops::TotalOrd for I128 { } impl I128 { - /// The size of this type in bits. - /// - /// # Returns - /// - /// [u64] - The defined size of the `I128` type. + /// The smallest value that can be represented by this integer type. /// /// # Examples /// - /// ``sway + /// ```sway /// use sway_libs::signed_integers::i128::I128; /// /// fn foo() { - /// let bits = I128::bits(); - /// assert(bits == 128); + /// let i128 = I128::MIN; + /// assert(i128.underlying() == U128::min()); /// } /// ``` - pub fn bits() -> u64 { - 128 - } + const MIN: Self = Self { + underlying: U128::min(), + }; - /// Helper function to get a positive value from an unsigned number. - /// - /// # Arguments - /// - /// * `underlying`: [U128] - The unsigned number to become the underlying value for the `I128`. + /// The largest value that can be represented by this integer type. /// /// # Returns /// @@ -110,46 +102,45 @@ impl I128 { /// /// ```sway /// use sway_libs::signed_integers::i128::I128; - /// use std::U128::*; /// /// fn foo() { - /// let underlying = U128::from((0, 1)); - /// let i128 = I128::from_uint(underlying); - /// assert(i128.underlying() == underlying); + /// let i128 = I128::MAX; + /// assert(i128.underlying() == U128::max()); /// } /// ``` - pub fn from_uint(underlying: U128) -> Self { - Self { underlying } - } + const MAX: Self = Self { + underlying: U128::max(), + }; - /// The largest value that can be represented by this integer type. + /// The size of this type in bits. /// /// # Returns /// - /// * [I128] - The newly created `I128` struct. + /// [u64] - The defined size of the `I128` type. /// /// # Examples /// - /// ```sway + /// ``sway /// use sway_libs::signed_integers::i128::I128; - /// use std::U128::*; /// /// fn foo() { - /// let i128 = I128::max(); - /// assert(i128.underlying() == U128::max()); + /// let bits = I128::bits(); + /// assert(bits == 128); /// } /// ``` - pub fn max() -> Self { - Self { - underlying: U128::max(), - } + pub fn bits() -> u64 { + 128 } - /// The smallest value that can be represented by this integer type. + /// Helper function to get a positive value from an unsigned number. + /// + /// # Arguments + /// + /// * `underlying`: [U128] - The unsigned number to become the underlying value for the `I128`. /// /// # Returns /// - /// * [I128] - The newly created `I128` type. + /// * [I128] - The newly created `I128` struct. /// /// # Examples /// @@ -158,14 +149,13 @@ impl I128 { /// use std::U128::*; /// /// fn foo() { - /// let i128 = I128::min(); - /// assert(i128.underlying() == U128::min()); + /// let underlying = U128::from((0, 1)); + /// let i128 = I128::from_uint(underlying); + /// assert(i128.underlying() == underlying); /// } /// ``` - pub fn min() -> Self { - Self { - underlying: U128::min(), - } + pub fn from_uint(underlying: U128) -> Self { + Self { underlying } } /// Helper function to get a negative value of an unsigned number. @@ -413,8 +403,12 @@ impl core::ops::Subtract for I128 { impl WrappingNeg for I128 { fn wrapping_neg(self) -> Self { - if self == self::min() { - return self::min() + // TODO: Replace the hardcoded min with Self::MIN once https://github.com/FuelLabs/sway/issues/6772 is closed + let min = Self { + underlying: U128::min() + }; + if self == min { + return min } self * Self::neg_try_from(U128::from((0, 1))).unwrap() } diff --git a/libs/src/signed_integers/i16.sw b/libs/src/signed_integers/i16.sw index 2d7a2e05..461d2a44 100644 --- a/libs/src/signed_integers/i16.sw +++ b/libs/src/signed_integers/i16.sw @@ -75,31 +75,23 @@ impl core::ops::TotalOrd for I16 { } impl I16 { - /// The size of this type in bits. - /// - /// # Returns - /// - /// [u64] - The defined size of the `I16` type. + /// The smallest value that can be represented by this integer type. /// /// # Examples /// - /// ``sway + /// ```sway /// use sway_libs::signed_integers::i16::I16; /// /// fn foo() { - /// let bits = I16::bits(); - /// assert(bits == 16); + /// let i16 = I16::MIN; + /// assert(i16.underlying() == u16::min()); /// } /// ``` - pub fn bits() -> u64 { - 16 - } + const MIN: Self = Self { + underlying: u16::min(), + }; - /// Helper function to get a positive value from an unsigned number - /// - /// # Arguments - /// - /// * `underlying`: [u16] - The unsigned number to become the underlying value for the `I16`. + /// The largest value that can be represented by this integer type. /// /// # Returns /// @@ -111,42 +103,43 @@ impl I16 { /// use sway_libs::signed_integers::i16::I16; /// /// fn foo() { - /// let underlying = 1u16; - /// let i16 = I16::from_uint(underlying); - /// assert(i16.underlying() == underlying); + /// let i16 = I16::MAX; + /// assert(i16.underlying() == u16::max()); /// } /// ``` - pub fn from_uint(underlying: u16) -> Self { - Self { underlying } - } + const MAX: Self = Self { + underlying: u16::max(), + }; - /// The largest value that can be represented by this integer type. + /// The size of this type in bits. /// /// # Returns /// - /// * [I16] - The newly created `I16` struct. + /// [u64] - The defined size of the `I16` type. /// /// # Examples /// - /// ```sway + /// ``sway /// use sway_libs::signed_integers::i16::I16; /// /// fn foo() { - /// let i16 = I16::max(); - /// assert(i16.underlying() == u16::max()); + /// let bits = I16::bits(); + /// assert(bits == 16); /// } /// ``` - pub fn max() -> Self { - Self { - underlying: u16::max(), - } + pub fn bits() -> u64 { + 16 } - /// The smallest value that can be represented by this integer type. + /// Helper function to get a positive value from an unsigned number + /// + /// # Arguments + /// + /// * `underlying`: [u16] - The unsigned number to become the underlying value for the `I16`. /// /// # Returns /// - /// * [I16] - The newly created `I16` type. + /// * [I16] - The newly created `I16` struct. /// /// # Examples /// @@ -154,14 +147,13 @@ impl I16 { /// use sway_libs::signed_integers::i16::I16; /// /// fn foo() { - /// let i16 = I16::min(); - /// assert(i16.underlying() == u16::min()); + /// let underlying = 1u16; + /// let i16 = I16::from_uint(underlying); + /// assert(i16.underlying() == underlying); /// } /// ``` - pub fn min() -> Self { - Self { - underlying: u16::min(), - } + pub fn from_uint(underlying: u16) -> Self { + Self { underlying } } /// Helper function to get a negative value of an unsigned number. @@ -401,8 +393,12 @@ impl core::ops::Subtract for I16 { impl WrappingNeg for I16 { fn wrapping_neg(self) -> Self { - if self == self::min() { - return self::min() + // TODO: Replace the hardcoded min with Self::MIN once https://github.com/FuelLabs/sway/issues/6772 is closed + let min = Self { + underlying: u16::min(), + }; + if self == min { + return min } self * Self::neg_try_from(1u16).unwrap() } diff --git a/libs/src/signed_integers/i256.sw b/libs/src/signed_integers/i256.sw index 81fb7648..94779d13 100644 --- a/libs/src/signed_integers/i256.sw +++ b/libs/src/signed_integers/i256.sw @@ -78,31 +78,23 @@ impl core::ops::TotalOrd for I256 { } impl I256 { - /// The size of this type in bits. - /// - /// # Returns - /// - /// [u64] - The defined size of the `I256` type. + /// The smallest value that can be represented by this integer type. /// /// # Examples /// - /// ``sway + /// ```sway /// use sway_libs::signed_integers::i256::I256; /// /// fn foo() { - /// let bits = I256::bits(); - /// assert(bits == 256); + /// let i256 = I256::MIN; + /// assert(i256.underlying() == u256::min()); /// } /// ``` - pub fn bits() -> u64 { - 256 - } + const MIN: Self = Self { + underlying: u256::min(), + }; - /// Helper function to get a signed number from with an underlying. - /// - /// # Arguments - /// - /// * `underlying`: [u256] - The unsigned number to become the underlying value for the `I256`. + /// The largest value that can be represented by this integer type. /// /// # Returns /// @@ -114,42 +106,43 @@ impl I256 { /// use sway_libs::signed_integers::i256::I256; /// /// fn foo() { - /// let underlying = 0x0000000000000000000000000000000000000000000000000000000000000001u256; - /// let i256 = I256::from_uint(underlying); - /// assert(i256.underlying() == underlying); + /// let i256 = I256::MAX; + /// assert(i256.underlying() == u256::max()); /// } /// ``` - pub fn from_uint(underlying: u256) -> Self { - Self { underlying } - } + const MAX: Self = Self { + underlying: u256::max(), + }; - /// The largest value that can be represented by this integer type. + /// The size of this type in bits. /// /// # Returns /// - /// * [I256] - The newly created `I256` struct. + /// [u64] - The defined size of the `I256` type. /// /// # Examples /// - /// ```sway + /// ``sway /// use sway_libs::signed_integers::i256::I256; /// /// fn foo() { - /// let i256 = I256::max(); - /// assert(i256.underlying() == u256::max()); + /// let bits = I256::bits(); + /// assert(bits == 256); /// } /// ``` - pub fn max() -> Self { - Self { - underlying: u256::max(), - } + pub fn bits() -> u64 { + 256 } - /// The smallest value that can be represented by this integer type. + /// Helper function to get a signed number from with an underlying. + /// + /// # Arguments + /// + /// * `underlying`: [u256] - The unsigned number to become the underlying value for the `I256`. /// /// # Returns /// - /// * [I256] - The newly created `I256` type. + /// * [I256] - The newly created `I256` struct. /// /// # Examples /// @@ -157,14 +150,13 @@ impl I256 { /// use sway_libs::signed_integers::i256::I256; /// /// fn foo() { - /// let i256 = I256::min(); - /// assert(i256.underlying() == u256::min()); + /// let underlying = 0x0000000000000000000000000000000000000000000000000000000000000001u256; + /// let i256 = I256::from_uint(underlying); + /// assert(i256.underlying() == underlying); /// } /// ``` - pub fn min() -> Self { - Self { - underlying: u256::min(), - } + pub fn from_uint(underlying: u256) -> Self { + Self { underlying } } /// Helper function to get a negative value of an unsigned number. @@ -392,8 +384,12 @@ impl core::ops::Subtract for I256 { impl WrappingNeg for I256 { fn wrapping_neg(self) -> Self { - if self == self::min() { - return self::min() + // TODO: Replace the hardcoded min with Self::MIN once https://github.com/FuelLabs/sway/issues/6772 is closed + let min = Self { + underlying: u256::min() + }; + if self == min { + return min } self * Self::neg_try_from(0x0000000000000000000000000000000000000000000000000000000000000001u256).unwrap() } diff --git a/libs/src/signed_integers/i32.sw b/libs/src/signed_integers/i32.sw index b3a1301c..af3a4c5a 100644 --- a/libs/src/signed_integers/i32.sw +++ b/libs/src/signed_integers/i32.sw @@ -75,31 +75,23 @@ impl core::ops::TotalOrd for I32 { } impl I32 { - /// The size of this type in bits. - /// - /// # Returns - /// - /// [u64] - The defined size of the `I32` type. + /// The smallest value that can be represented by this integer type. /// /// # Examples /// - /// ``sway + /// ```sway /// use sway_libs::signed_integers::i32::I32; /// /// fn foo() { - /// let bits = I32::bits(); - /// assert(bits == 32); + /// let i32 = I32::MIN; + /// assert(i32.underlying() == u32::min()); /// } /// ``` - pub fn bits() -> u64 { - 32 - } + const MIN: Self = Self { + underlying: u32::min(), + }; - /// Helper function to get a signed number from with an underlying. - /// - /// # Arguments - /// - /// * `underlying`: [u32] - The unsigned number to become the underlying value for the `I32`. + /// The largest value that can be represented by this integer type. /// /// # Returns /// @@ -111,42 +103,43 @@ impl I32 { /// use sway_libs::signed_integers::i32::I32; /// /// fn foo() { - /// let underlying = 1u32; - /// let i32 = I32::from_uint(underlying); - /// assert(i32.underlying() == underlying); + /// let i32 = I32::MAX; + /// assert(i32.underlying() == u32::max()); /// } /// ``` - pub fn from_uint(underlying: u32) -> Self { - Self { underlying } - } + const MAX: Self = Self { + underlying: u32::max(), + }; - /// The largest value that can be represented by this integer type. + /// The size of this type in bits. /// /// # Returns /// - /// * [I32] - The newly created `I32` struct. + /// [u64] - The defined size of the `I32` type. /// /// # Examples /// - /// ```sway + /// ``sway /// use sway_libs::signed_integers::i32::I32; /// /// fn foo() { - /// let i32 = I32::max(); - /// assert(i32.underlying() == u32::max()); + /// let bits = I32::bits(); + /// assert(bits == 32); /// } /// ``` - pub fn max() -> Self { - Self { - underlying: u32::max(), - } + pub fn bits() -> u64 { + 32 } - /// The smallest value that can be represented by this integer type. + /// Helper function to get a signed number from with an underlying. + /// + /// # Arguments + /// + /// * `underlying`: [u32] - The unsigned number to become the underlying value for the `I32`. /// /// # Returns /// - /// * [I32] - The newly created `I32` type. + /// * [I32] - The newly created `I32` struct. /// /// # Examples /// @@ -154,14 +147,13 @@ impl I32 { /// use sway_libs::signed_integers::i32::I32; /// /// fn foo() { - /// let i32 = I32::min(); - /// assert(i32.underlying() == u32::min()); + /// let underlying = 1u32; + /// let i32 = I32::from_uint(underlying); + /// assert(i32.underlying() == underlying); /// } /// ``` - pub fn min() -> Self { - Self { - underlying: u32::min(), - } + pub fn from_uint(underlying: u32) -> Self { + Self { underlying } } /// Helper function to get a negative value of an unsigned numbers. @@ -401,8 +393,12 @@ impl core::ops::Divide for I32 { impl WrappingNeg for I32 { fn wrapping_neg(self) -> Self { - if self == self::min() { - return self::min() + // TODO: Replace the hardcoded min with Self::MIN once https://github.com/FuelLabs/sway/issues/6772 is closed + let min = Self { + underlying: u32::min() + }; + if self == min { + return min } self * Self::neg_try_from(1u32).unwrap() } diff --git a/libs/src/signed_integers/i64.sw b/libs/src/signed_integers/i64.sw index 2d53aae6..5dffaec8 100644 --- a/libs/src/signed_integers/i64.sw +++ b/libs/src/signed_integers/i64.sw @@ -75,31 +75,23 @@ impl core::ops::TotalOrd for I64 { } impl I64 { - /// The size of this type in bits. - /// - /// # Returns - /// - /// [u64] - The defined size of the `I64` type. + /// The smallest value that can be represented by this integer type. /// /// # Examples /// - /// ``sway + /// ```sway /// use sway_libs::signed_integers::i64::I64; /// /// fn foo() { - /// let bits = I64::bits(); - /// assert(bits == 64); + /// let i64 = I64::MIN; + /// assert(i64.underlying() == u64::min()); /// } /// ``` - pub fn bits() -> u64 { - 64 - } + const MIN: Self = Self { + underlying: u64::min(), + }; - /// Helper function to get a signed number from with an underlying. - /// - /// # Arguments - /// - /// * `underlying`: [u64] - The unsigned number to become the underlying value for the `I64`. + /// The largest value that can be represented by this integer type. /// /// # Returns /// @@ -111,42 +103,43 @@ impl I64 { /// use sway_libs::signed_integers::i64::I64; /// /// fn foo() { - /// let underlying = 1u64; - /// let i64 = I64::from_uint(underlying); - /// assert(i64.underlying() == underlying); + /// let i64 = I64::MAX; + /// assert(i64.underlying() == u64::max()); /// } /// ``` - pub fn from_uint(underlying: u64) -> Self { - Self { underlying } - } + const MAX: Self = Self { + underlying: u64::max(), + }; - /// The largest value that can be represented by this integer type. + /// The size of this type in bits. /// /// # Returns /// - /// * [I64] - The newly created `I64` struct. + /// [u64] - The defined size of the `I64` type. /// /// # Examples /// - /// ```sway + /// ``sway /// use sway_libs::signed_integers::i64::I64; /// /// fn foo() { - /// let i64 = I64::max(); - /// assert(i64.underlying() == u64::max()); + /// let bits = I64::bits(); + /// assert(bits == 64); /// } /// ``` - pub fn max() -> Self { - Self { - underlying: u64::max(), - } + pub fn bits() -> u64 { + 64 } - /// The smallest value that can be represented by this integer type. + /// Helper function to get a signed number from with an underlying. + /// + /// # Arguments + /// + /// * `underlying`: [u64] - The unsigned number to become the underlying value for the `I64`. /// /// # Returns /// - /// * [I64] - The newly created `I64` type. + /// * [I64] - The newly created `I64` struct. /// /// # Examples /// @@ -154,14 +147,13 @@ impl I64 { /// use sway_libs::signed_integers::i64::I64; /// /// fn foo() { - /// let i64 = I64::min(); - /// assert(i64.underlying() == u64::min()); + /// let underlying = 1u64; + /// let i64 = I64::from_uint(underlying); + /// assert(i64.underlying() == underlying); /// } /// ``` - pub fn min() -> Self { - Self { - underlying: u64::min(), - } + pub fn from_uint(underlying: u64) -> Self { + Self { underlying } } /// Helper function to get a negative value of an unsigned number. @@ -402,8 +394,12 @@ impl core::ops::Divide for I64 { impl WrappingNeg for I64 { fn wrapping_neg(self) -> Self { - if self == self::min() { - return self::min() + // TODO: Replace the hardcoded min with Self::MIN once https://github.com/FuelLabs/sway/issues/6772 is closed + let min = Self { + underlying: u64::min() + }; + if self == min { + return min } self * Self::neg_try_from(1).unwrap() } diff --git a/libs/src/signed_integers/i8.sw b/libs/src/signed_integers/i8.sw index 8371efbc..e2e9b166 100644 --- a/libs/src/signed_integers/i8.sw +++ b/libs/src/signed_integers/i8.sw @@ -393,8 +393,12 @@ impl core::ops::Subtract for I8 { impl WrappingNeg for I8 { fn wrapping_neg(self) -> Self { - if self == Self::MIN { - return Self::MIN + // TODO: Replace the hardcoded min with Self::MIN once https://github.com/FuelLabs/sway/issues/6772 is closed + let min = Self { + underlying: u8::min(), + }; + if self == min { + return min } self * Self::neg_try_from(1u8).unwrap() } From 81fcc284de9a6fbd7ff8b3f6ebfe5ce93a193abd Mon Sep 17 00:00:00 2001 From: SwayStar123 Date: Mon, 9 Dec 2024 15:22:07 +0530 Subject: [PATCH 5/7] fmt --- libs/src/signed_integers/i128.sw | 2 +- libs/src/signed_integers/i32.sw | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/src/signed_integers/i128.sw b/libs/src/signed_integers/i128.sw index e3ba9be5..83986be8 100644 --- a/libs/src/signed_integers/i128.sw +++ b/libs/src/signed_integers/i128.sw @@ -405,7 +405,7 @@ impl WrappingNeg for I128 { fn wrapping_neg(self) -> Self { // TODO: Replace the hardcoded min with Self::MIN once https://github.com/FuelLabs/sway/issues/6772 is closed let min = Self { - underlying: U128::min() + underlying: U128::min(), }; if self == min { return min diff --git a/libs/src/signed_integers/i32.sw b/libs/src/signed_integers/i32.sw index af3a4c5a..c994a7c9 100644 --- a/libs/src/signed_integers/i32.sw +++ b/libs/src/signed_integers/i32.sw @@ -395,7 +395,7 @@ impl WrappingNeg for I32 { fn wrapping_neg(self) -> Self { // TODO: Replace the hardcoded min with Self::MIN once https://github.com/FuelLabs/sway/issues/6772 is closed let min = Self { - underlying: u32::min() + underlying: u32::min(), }; if self == min { return min From f19eb5d2b952f957c4337d91eca718a46c348333 Mon Sep 17 00:00:00 2001 From: SwayStar123 Date: Mon, 9 Dec 2024 15:26:57 +0530 Subject: [PATCH 6/7] fmt --- libs/src/signed_integers/i256.sw | 2 +- libs/src/signed_integers/i64.sw | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/src/signed_integers/i256.sw b/libs/src/signed_integers/i256.sw index 94779d13..dc41a19d 100644 --- a/libs/src/signed_integers/i256.sw +++ b/libs/src/signed_integers/i256.sw @@ -386,7 +386,7 @@ impl WrappingNeg for I256 { fn wrapping_neg(self) -> Self { // TODO: Replace the hardcoded min with Self::MIN once https://github.com/FuelLabs/sway/issues/6772 is closed let min = Self { - underlying: u256::min() + underlying: u256::min(), }; if self == min { return min diff --git a/libs/src/signed_integers/i64.sw b/libs/src/signed_integers/i64.sw index 5dffaec8..8ab17451 100644 --- a/libs/src/signed_integers/i64.sw +++ b/libs/src/signed_integers/i64.sw @@ -396,7 +396,7 @@ impl WrappingNeg for I64 { fn wrapping_neg(self) -> Self { // TODO: Replace the hardcoded min with Self::MIN once https://github.com/FuelLabs/sway/issues/6772 is closed let min = Self { - underlying: u64::min() + underlying: u64::min(), }; if self == min { return min From 24b3a4bcde4e6707493fc692fe63c50a5025aa8d Mon Sep 17 00:00:00 2001 From: SwayStar123 Date: Mon, 9 Dec 2024 15:42:25 +0530 Subject: [PATCH 7/7] make new forc lock, fix tests --- tests/Forc.lock | 4 ++-- tests/src/signed_integers/signed_i128/src/main.sw | 14 +++++++------- .../signed_i128_wrapping_neg/src/main.sw | 6 +++--- tests/src/signed_integers/signed_i16/src/main.sw | 14 +++++++------- .../signed_i16_wrapping_neg/src/main.sw | 6 +++--- tests/src/signed_integers/signed_i256/src/main.sw | 14 +++++++------- .../signed_i256_wrapping_neg/src/main.sw | 6 +++--- tests/src/signed_integers/signed_i32/src/main.sw | 14 +++++++------- .../signed_i32_wrapping_neg/src/main.sw | 6 +++--- tests/src/signed_integers/signed_i64/src/main.sw | 14 +++++++------- .../signed_i64_wrapping_neg/src/main.sw | 6 +++--- tests/src/signed_integers/signed_i8/src/main.sw | 14 +++++++------- .../signed_i8_wrapping_neg/src/main.sw | 6 +++--- 13 files changed, 62 insertions(+), 62 deletions(-) diff --git a/tests/Forc.lock b/tests/Forc.lock index e43ad271..0071cb0e 100644 --- a/tests/Forc.lock +++ b/tests/Forc.lock @@ -22,7 +22,7 @@ dependencies = ["std"] [[package]] name = "core" -source = "path+from-root-7053AAA90CC5E690" +source = "path+from-root-6A8836696D55BC6E" [[package]] name = "i128_test" @@ -221,7 +221,7 @@ dependencies = ["std"] [[package]] name = "std" -source = "git+https://github.com/fuellabs/sway?tag=v0.66.2#31486c0b47669612acb7c64d66ecb50aea281282" +source = "git+https://github.com/fuellabs/sway?tag=v0.66.5#94a066652468b4afa3bd396dacef482ed590976b" dependencies = ["core"] [[package]] diff --git a/tests/src/signed_integers/signed_i128/src/main.sw b/tests/src/signed_integers/signed_i128/src/main.sw index 1f96cf05..1e0ebb7a 100644 --- a/tests/src/signed_integers/signed_i128/src/main.sw +++ b/tests/src/signed_integers/signed_i128/src/main.sw @@ -69,10 +69,10 @@ fn main() -> bool { let one_2 = I128::try_from(U128::from((0, 1))).unwrap(); let neg_one_1 = I128::neg_try_from(U128::from((0, 1))).unwrap(); let neg_one_2 = I128::neg_try_from(U128::from((0, 1))).unwrap(); - let max_1 = I128::max(); - let max_2 = I128::max(); - let min_1 = I128::min(); - let min_2 = I128::min(); + let max_1 = I128::MAX; + let max_2 = I128::MAX; + let min_1 = I128::MIN; + let min_2 = I128::MIN; assert(one_1 >= one_2); assert(one_1 <= one_2); @@ -120,7 +120,7 @@ fn main() -> bool { let i128_max_try_from = I128::try_from(indent); assert(i128_max_try_from.is_some()); - assert(i128_max_try_from.unwrap() == I128::max()); + assert(i128_max_try_from.unwrap() == I128::MAX); let i128_min_try_from = I128::try_from(U128::min()); assert(i128_min_try_from.is_some()); @@ -131,7 +131,7 @@ fn main() -> bool { let i128_max_try_into: Option = indent.try_into(); assert(i128_max_try_into.is_some()); - assert(i128_max_try_into.unwrap() == I128::max()); + assert(i128_max_try_into.unwrap() == I128::MAX); let i128_min_try_into: Option = U128::min().try_into(); assert(i128_min_try_into.is_some()); @@ -143,7 +143,7 @@ fn main() -> bool { // Test into U128 let zero = I128::zero(); let negative = I128::neg_try_from(U128::from((0, 1))).unwrap(); - let max = I128::max(); + let max = I128::MAX; let U128_max_try_from: Option = U128::try_from(max); assert(U128_max_try_from.is_some()); diff --git a/tests/src/signed_integers/signed_i128_wrapping_neg/src/main.sw b/tests/src/signed_integers/signed_i128_wrapping_neg/src/main.sw index 802d8705..29ccfcc0 100644 --- a/tests/src/signed_integers/signed_i128_wrapping_neg/src/main.sw +++ b/tests/src/signed_integers/signed_i128_wrapping_neg/src/main.sw @@ -20,9 +20,9 @@ fn main() -> bool { let neg_ninty_three = I128::neg_try_from(U128::from(93u64)).unwrap(); let zero = I128::try_from(U128::zero()).unwrap(); - let max = I128::max(); - let min = I128::min(); - let neg_min_plus_one = I128::min() + I128::try_from(U128::from((0, 1))).unwrap(); + let max = I128::MAX; + let min = I128::MIN; + let neg_min_plus_one = I128::MIN + I128::try_from(U128::from((0, 1))).unwrap(); let res1 = one.wrapping_neg(); let res2 = neg_one.wrapping_neg(); diff --git a/tests/src/signed_integers/signed_i16/src/main.sw b/tests/src/signed_integers/signed_i16/src/main.sw index a50a3ff0..f1b6feff 100644 --- a/tests/src/signed_integers/signed_i16/src/main.sw +++ b/tests/src/signed_integers/signed_i16/src/main.sw @@ -57,10 +57,10 @@ fn main() -> bool { let one_2 = I16::try_from(1u16).unwrap(); let neg_one_1 = I16::neg_try_from(1u16).unwrap(); let neg_one_2 = I16::neg_try_from(1u16).unwrap(); - let max_1 = I16::max(); - let max_2 = I16::max(); - let min_1 = I16::min(); - let min_2 = I16::min(); + let max_1 = I16::MAX; + let max_2 = I16::MAX; + let min_1 = I16::MIN; + let min_2 = I16::MIN; assert(one_1 >= one_2); assert(one_1 <= one_2); @@ -108,7 +108,7 @@ fn main() -> bool { let i16_max_try_from = I16::try_from(indent); assert(i16_max_try_from.is_some()); - assert(i16_max_try_from.unwrap() == I16::max()); + assert(i16_max_try_from.unwrap() == I16::MAX); let i16_min_try_from = I16::try_from(u16::min()); assert(i16_min_try_from.is_some()); @@ -119,7 +119,7 @@ fn main() -> bool { let i16_max_try_into: Option = indent.try_into(); assert(i16_max_try_into.is_some()); - assert(i16_max_try_into.unwrap() == I16::max()); + assert(i16_max_try_into.unwrap() == I16::MAX); let i16_min_try_into: Option = u16::min().try_into(); assert(i16_min_try_into.is_some()); @@ -131,7 +131,7 @@ fn main() -> bool { // Test into u16 let zero = I16::zero(); let negative = I16::neg_try_from(1).unwrap(); - let max = I16::max(); + let max = I16::MAX; let u16_max_try_from: Option = u16::try_from(max); assert(u16_max_try_from.is_some()); diff --git a/tests/src/signed_integers/signed_i16_wrapping_neg/src/main.sw b/tests/src/signed_integers/signed_i16_wrapping_neg/src/main.sw index 50366666..a9909323 100644 --- a/tests/src/signed_integers/signed_i16_wrapping_neg/src/main.sw +++ b/tests/src/signed_integers/signed_i16_wrapping_neg/src/main.sw @@ -19,9 +19,9 @@ fn main() -> bool { let neg_ninty_three = I16::neg_try_from(93u16).unwrap(); let zero = I16::try_from(0u16).unwrap(); - let max = I16::max(); - let min = I16::min(); - let neg_min_plus_one = I16::min() + I16::try_from(1u16).unwrap(); + let max = I16::MAX; + let min = I16::MIN; + let neg_min_plus_one = I16::MIN + I16::try_from(1u16).unwrap(); let res1 = one.wrapping_neg(); let res2 = neg_one.wrapping_neg(); diff --git a/tests/src/signed_integers/signed_i256/src/main.sw b/tests/src/signed_integers/signed_i256/src/main.sw index 5de73526..91948663 100644 --- a/tests/src/signed_integers/signed_i256/src/main.sw +++ b/tests/src/signed_integers/signed_i256/src/main.sw @@ -102,10 +102,10 @@ fn main() -> bool { let one_2 = I256::try_from(u256_one).unwrap(); let neg_one_1 = I256::neg_try_from(u256_one).unwrap(); let neg_one_2 = I256::neg_try_from(u256_one).unwrap(); - let max_1 = I256::max(); - let max_2 = I256::max(); - let min_1 = I256::min(); - let min_2 = I256::min(); + let max_1 = I256::MAX; + let max_2 = I256::MAX; + let min_1 = I256::MIN; + let min_2 = I256::MIN; assert(one_1 >= one_2); assert(one_1 <= one_2); @@ -153,7 +153,7 @@ fn main() -> bool { let i256_max_try_from = I256::try_from(indent); assert(i256_max_try_from.is_some()); - assert(i256_max_try_from.unwrap() == I256::max()); + assert(i256_max_try_from.unwrap() == I256::MAX); let i256_min_try_from = I256::try_from(u256::min()); assert(i256_min_try_from.is_some()); @@ -164,7 +164,7 @@ fn main() -> bool { let i256_max_try_into: Option = indent.try_into(); assert(i256_max_try_into.is_some()); - assert(i256_max_try_into.unwrap() == I256::max()); + assert(i256_max_try_into.unwrap() == I256::MAX); let i256_min_try_into: Option = u256::min().try_into(); assert(i256_min_try_into.is_some()); @@ -176,7 +176,7 @@ fn main() -> bool { // Test into u256 let zero = I256::zero(); let negative = I256::neg_try_from(u256_one).unwrap(); - let max = I256::max(); + let max = I256::MAX; let u256_max_try_from: Option = u256::try_from(max); assert(u256_max_try_from.is_some()); diff --git a/tests/src/signed_integers/signed_i256_wrapping_neg/src/main.sw b/tests/src/signed_integers/signed_i256_wrapping_neg/src/main.sw index 5260df80..aae03882 100644 --- a/tests/src/signed_integers/signed_i256_wrapping_neg/src/main.sw +++ b/tests/src/signed_integers/signed_i256_wrapping_neg/src/main.sw @@ -40,9 +40,9 @@ fn main() -> bool { let neg_ninty_three = I256::neg_try_from(u_ninty_three).unwrap(); let zero = I256::try_from(u256::zero()).unwrap(); - let max = I256::max(); - let min = I256::min(); - let neg_min_plus_one = I256::min() + I256::try_from(u_one).unwrap(); + let max = I256::MAX; + let min = I256::MIN; + let neg_min_plus_one = I256::MIN + I256::try_from(u_one).unwrap(); let res1 = one.wrapping_neg(); let res2 = neg_one.wrapping_neg(); diff --git a/tests/src/signed_integers/signed_i32/src/main.sw b/tests/src/signed_integers/signed_i32/src/main.sw index bd55869f..f646d967 100644 --- a/tests/src/signed_integers/signed_i32/src/main.sw +++ b/tests/src/signed_integers/signed_i32/src/main.sw @@ -57,10 +57,10 @@ fn main() -> bool { let one_2 = I32::try_from(1u32).unwrap(); let neg_one_1 = I32::neg_try_from(1u32).unwrap(); let neg_one_2 = I32::neg_try_from(1u32).unwrap(); - let max_1 = I32::max(); - let max_2 = I32::max(); - let min_1 = I32::min(); - let min_2 = I32::min(); + let max_1 = I32::MAX; + let max_2 = I32::MAX; + let min_1 = I32::MIN; + let min_2 = I32::MIN; assert(one_1 >= one_2); assert(one_1 <= one_2); @@ -108,7 +108,7 @@ fn main() -> bool { let i32_max_try_from = I32::try_from(indent); assert(i32_max_try_from.is_some()); - assert(i32_max_try_from.unwrap() == I32::max()); + assert(i32_max_try_from.unwrap() == I32::MAX); let i32_min_try_from = I32::try_from(u32::min()); assert(i32_min_try_from.is_some()); @@ -119,7 +119,7 @@ fn main() -> bool { let i32_max_try_into: Option = indent.try_into(); assert(i32_max_try_into.is_some()); - assert(i32_max_try_into.unwrap() == I32::max()); + assert(i32_max_try_into.unwrap() == I32::MAX); let i32_min_try_into: Option = u32::min().try_into(); assert(i32_min_try_into.is_some()); @@ -131,7 +131,7 @@ fn main() -> bool { // Test into u32 let zero = I32::zero(); let negative = I32::neg_try_from(1).unwrap(); - let max = I32::max(); + let max = I32::MAX; let u32_max_try_from: Option = u32::try_from(max); assert(u32_max_try_from.is_some()); diff --git a/tests/src/signed_integers/signed_i32_wrapping_neg/src/main.sw b/tests/src/signed_integers/signed_i32_wrapping_neg/src/main.sw index bdb2c19f..064ac301 100644 --- a/tests/src/signed_integers/signed_i32_wrapping_neg/src/main.sw +++ b/tests/src/signed_integers/signed_i32_wrapping_neg/src/main.sw @@ -19,9 +19,9 @@ fn main() -> bool { let neg_ninty_three = I32::neg_try_from(93u32).unwrap(); let zero = I32::try_from(0u32).unwrap(); - let max = I32::max(); - let min = I32::min(); - let neg_min_plus_one = I32::min() + I32::try_from(1u32).unwrap(); + let max = I32::MAX; + let min = I32::MIN; + let neg_min_plus_one = I32::MIN + I32::try_from(1u32).unwrap(); let res1 = one.wrapping_neg(); let res2 = neg_one.wrapping_neg(); diff --git a/tests/src/signed_integers/signed_i64/src/main.sw b/tests/src/signed_integers/signed_i64/src/main.sw index 1d7a9881..f7efa40d 100644 --- a/tests/src/signed_integers/signed_i64/src/main.sw +++ b/tests/src/signed_integers/signed_i64/src/main.sw @@ -56,10 +56,10 @@ fn main() -> bool { let one_2 = I64::try_from(1u64).unwrap(); let neg_one_1 = I64::neg_try_from(1u64).unwrap(); let neg_one_2 = I64::neg_try_from(1u64).unwrap(); - let max_1 = I64::max(); - let max_2 = I64::max(); - let min_1 = I64::min(); - let min_2 = I64::min(); + let max_1 = I64::MAX; + let max_2 = I64::MAX; + let min_1 = I64::MIN; + let min_2 = I64::MIN; assert(one_1 >= one_2); assert(one_1 <= one_2); @@ -107,7 +107,7 @@ fn main() -> bool { let i64_max_try_from = I64::try_from(indent); assert(i64_max_try_from.is_some()); - assert(i64_max_try_from.unwrap() == I64::max()); + assert(i64_max_try_from.unwrap() == I64::MAX); let i64_min_try_from = I64::try_from(u64::min()); assert(i64_min_try_from.is_some()); @@ -118,7 +118,7 @@ fn main() -> bool { let i64_max_try_into: Option = indent.try_into(); assert(i64_max_try_into.is_some()); - assert(i64_max_try_into.unwrap() == I64::max()); + assert(i64_max_try_into.unwrap() == I64::MAX); let i64_min_try_into: Option = u64::min().try_into(); assert(i64_min_try_into.is_some()); @@ -130,7 +130,7 @@ fn main() -> bool { // Test into u64 let zero = I64::zero(); let negative = I64::neg_try_from(1).unwrap(); - let max = I64::max(); + let max = I64::MAX; let u64_max_try_from: Option = u64::try_from(max); assert(u64_max_try_from.is_some()); diff --git a/tests/src/signed_integers/signed_i64_wrapping_neg/src/main.sw b/tests/src/signed_integers/signed_i64_wrapping_neg/src/main.sw index e76f4d5c..59a639ad 100644 --- a/tests/src/signed_integers/signed_i64_wrapping_neg/src/main.sw +++ b/tests/src/signed_integers/signed_i64_wrapping_neg/src/main.sw @@ -19,9 +19,9 @@ fn main() -> bool { let neg_ninty_three = I64::neg_try_from(93u64).unwrap(); let zero = I64::try_from(0u64).unwrap(); - let max = I64::max(); - let min = I64::min(); - let neg_min_plus_one = I64::min() + I64::try_from(1).unwrap(); + let max = I64::MAX; + let min = I64::MIN; + let neg_min_plus_one = I64::MIN + I64::try_from(1).unwrap(); let res1 = one.wrapping_neg(); let res2 = neg_one.wrapping_neg(); diff --git a/tests/src/signed_integers/signed_i8/src/main.sw b/tests/src/signed_integers/signed_i8/src/main.sw index 31f97b8a..ea77bc5a 100644 --- a/tests/src/signed_integers/signed_i8/src/main.sw +++ b/tests/src/signed_integers/signed_i8/src/main.sw @@ -56,10 +56,10 @@ fn main() -> bool { let one_2 = I8::try_from(1u8).unwrap(); let neg_one_1 = I8::neg_try_from(1u8).unwrap(); let neg_one_2 = I8::neg_try_from(1u8).unwrap(); - let max_1 = I8::max(); - let max_2 = I8::max(); - let min_1 = I8::min(); - let min_2 = I8::min(); + let max_1 = I8::MAX; + let max_2 = I8::MAX; + let min_1 = I8::MIN; + let min_2 = I8::MIN; assert(one_1 >= one_2); assert(one_1 <= one_2); @@ -107,7 +107,7 @@ fn main() -> bool { let i8_max_try_from = I8::try_from(indent); assert(i8_max_try_from.is_some()); - assert(i8_max_try_from.unwrap() == I8::max()); + assert(i8_max_try_from.unwrap() == I8::MAX); let i8_min_try_from = I8::try_from(u8::min()); assert(i8_min_try_from.is_some()); @@ -118,7 +118,7 @@ fn main() -> bool { let i8_max_try_into: Option = indent.try_into(); assert(i8_max_try_into.is_some()); - assert(i8_max_try_into.unwrap() == I8::max()); + assert(i8_max_try_into.unwrap() == I8::MAX); let i8_min_try_into: Option = u8::min().try_into(); assert(i8_min_try_into.is_some()); @@ -130,7 +130,7 @@ fn main() -> bool { // Test into u8 let zero = I8::zero(); let negative = I8::neg_try_from(1).unwrap(); - let max = I8::max(); + let max = I8::MAX; let u8_max_try_from: Option = u8::try_from(max); assert(u8_max_try_from.is_some()); diff --git a/tests/src/signed_integers/signed_i8_wrapping_neg/src/main.sw b/tests/src/signed_integers/signed_i8_wrapping_neg/src/main.sw index 5282dcd6..e5aa16b4 100644 --- a/tests/src/signed_integers/signed_i8_wrapping_neg/src/main.sw +++ b/tests/src/signed_integers/signed_i8_wrapping_neg/src/main.sw @@ -19,9 +19,9 @@ fn main() -> bool { let neg_ninty_three = I8::neg_try_from(93u8).unwrap(); let zero = I8::try_from(0u8).unwrap(); - let max = I8::max(); - let min = I8::min(); - let neg_min_plus_one = I8::min() + I8::try_from(1u8).unwrap(); + let max = I8::MAX; + let min = I8::MIN; + let neg_min_plus_one = I8::MIN + I8::try_from(1u8).unwrap(); let res1 = one.wrapping_neg(); let res2 = neg_one.wrapping_neg();