From c3eb387c0b78511992db6b3e4fe850f01b1dcc76 Mon Sep 17 00:00:00 2001 From: SwayStar123 Date: Tue, 2 Jul 2024 15:02:02 +0000 Subject: [PATCH 1/9] fix ord --- libs/src/fixed_point/ifp128.sw | 21 +++++++++++++++------ libs/src/fixed_point/ifp256.sw | 21 +++++++++++++++------ libs/src/fixed_point/ifp64.sw | 21 +++++++++++++++------ 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/libs/src/fixed_point/ifp128.sw b/libs/src/fixed_point/ifp128.sw index b9457c1d..969b1512 100644 --- a/libs/src/fixed_point/ifp128.sw +++ b/libs/src/fixed_point/ifp128.sw @@ -206,11 +206,11 @@ impl core::ops::Eq for IFP128 { impl core::ops::Ord for IFP128 { fn gt(self, other: Self) -> bool { - if self.non_negative && !self.non_negative { + if self.non_negative && !other.non_negative { true - } else if !self.non_negative && self.non_negative { + } else if !self.non_negative && other.non_negative { false - } else if self.non_negative && self.non_negative { + } else if self.non_negative && other.non_negative { self.underlying > other.underlying } else { self.underlying < other.underlying @@ -218,11 +218,11 @@ impl core::ops::Ord for IFP128 { } fn lt(self, other: Self) -> bool { - if self.non_negative && !self.non_negative { + if self.non_negative && !other.non_negative { false - } else if !self.non_negative && self.non_negative { + } else if !self.non_negative && other.non_negative { true - } else if self.non_negative && self.non_negative { + } else if self.non_negative && other.non_negative { self.underlying < other.underlying } else { self.underlying > other.underlying @@ -568,3 +568,12 @@ impl Power for IFP128 { } } } + +#[test] +fn test_ord() { + let num = IFP128::from_uint(42_u64); + let num2 = IFP128::min(); + + assert(num > num2); + assert(num2 < num); +} diff --git a/libs/src/fixed_point/ifp256.sw b/libs/src/fixed_point/ifp256.sw index 9b7acf8f..4790005c 100644 --- a/libs/src/fixed_point/ifp256.sw +++ b/libs/src/fixed_point/ifp256.sw @@ -206,11 +206,11 @@ impl core::ops::Eq for IFP256 { impl core::ops::Ord for IFP256 { fn gt(self, other: Self) -> bool { - if self.non_negative && !self.non_negative { + if self.non_negative && !other.non_negative { true - } else if !self.non_negative && self.non_negative { + } else if !self.non_negative && other.non_negative { false - } else if self.non_negative && self.non_negative { + } else if self.non_negative && other.non_negative { self.underlying > other.underlying } else { self.underlying < other.underlying @@ -218,11 +218,11 @@ impl core::ops::Ord for IFP256 { } fn lt(self, other: Self) -> bool { - if self.non_negative && !self.non_negative { + if self.non_negative && !other.non_negative { false - } else if !self.non_negative && self.non_negative { + } else if !self.non_negative && other.non_negative { true - } else if self.non_negative && self.non_negative { + } else if self.non_negative && other.non_negative { self.underlying < other.underlying } else { self.underlying > other.underlying @@ -568,3 +568,12 @@ impl Power for IFP256 { } } } + +#[test] +fn test_ord() { + let num = IFP256::from_uint(42_u64); + let num2 = IFP256::min(); + + assert(num > num2); + assert(num2 < num); +} diff --git a/libs/src/fixed_point/ifp64.sw b/libs/src/fixed_point/ifp64.sw index 680536d6..4d5cd04d 100644 --- a/libs/src/fixed_point/ifp64.sw +++ b/libs/src/fixed_point/ifp64.sw @@ -206,11 +206,11 @@ impl core::ops::Eq for IFP64 { impl core::ops::Ord for IFP64 { fn gt(self, other: Self) -> bool { - if self.non_negative && !self.non_negative { + if self.non_negative && !other.non_negative { true - } else if !self.non_negative && self.non_negative { + } else if !self.non_negative && other.non_negative { false - } else if self.non_negative && self.non_negative { + } else if self.non_negative && other.non_negative { self.underlying > other.underlying } else { self.underlying < other.underlying @@ -218,11 +218,11 @@ impl core::ops::Ord for IFP64 { } fn lt(self, other: Self) -> bool { - if self.non_negative && !self.non_negative { + if self.non_negative && !other.non_negative { false - } else if !self.non_negative && self.non_negative { + } else if !self.non_negative && other.non_negative { true - } else if self.non_negative && self.non_negative { + } else if self.non_negative && other.non_negative { self.underlying < other.underlying } else { self.underlying > other.underlying @@ -568,3 +568,12 @@ impl Power for IFP64 { } } } + +#[test] +fn test_ord() { + let num = IFP64::from_uint(42_u32); + let num2 = IFP64::min(); + + assert(num > num2); + assert(num2 < num); +} \ No newline at end of file From ccc37616239eb12fbb225a8cdd8a29a04ba01486 Mon Sep 17 00:00:00 2001 From: SwayStar123 Date: Tue, 2 Jul 2024 15:02:20 +0000 Subject: [PATCH 2/9] fmt --- libs/src/fixed_point/ifp128.sw | 2 +- libs/src/fixed_point/ifp256.sw | 2 +- libs/src/fixed_point/ifp64.sw | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/src/fixed_point/ifp128.sw b/libs/src/fixed_point/ifp128.sw index 969b1512..6a2c3504 100644 --- a/libs/src/fixed_point/ifp128.sw +++ b/libs/src/fixed_point/ifp128.sw @@ -571,7 +571,7 @@ impl Power for IFP128 { #[test] fn test_ord() { - let num = IFP128::from_uint(42_u64); + let num = IFP128::from_uint(42_u64); let num2 = IFP128::min(); assert(num > num2); diff --git a/libs/src/fixed_point/ifp256.sw b/libs/src/fixed_point/ifp256.sw index 4790005c..46abb609 100644 --- a/libs/src/fixed_point/ifp256.sw +++ b/libs/src/fixed_point/ifp256.sw @@ -571,7 +571,7 @@ impl Power for IFP256 { #[test] fn test_ord() { - let num = IFP256::from_uint(42_u64); + let num = IFP256::from_uint(42_u64); let num2 = IFP256::min(); assert(num > num2); diff --git a/libs/src/fixed_point/ifp64.sw b/libs/src/fixed_point/ifp64.sw index 4d5cd04d..5700b7b0 100644 --- a/libs/src/fixed_point/ifp64.sw +++ b/libs/src/fixed_point/ifp64.sw @@ -571,9 +571,9 @@ impl Power for IFP64 { #[test] fn test_ord() { - let num = IFP64::from_uint(42_u32); + let num = IFP64::from_uint(42_u32); let num2 = IFP64::min(); assert(num > num2); assert(num2 < num); -} \ No newline at end of file +} From 876ab5936ac54c42e3738e8aef47eb537c207479 Mon Sep 17 00:00:00 2001 From: SwayStar123 Date: Tue, 2 Jul 2024 15:04:45 +0000 Subject: [PATCH 3/9] add temp changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1d0d98e..ed0cf25b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ Description of the upcoming release here. ### Fixed - [#258](https://github.com/FuelLabs/sway-libs/pull/258) Fixes incorrect intructions on how to run tests in README and docs hub. +- [#259](https://github.com/FuelLabs/sway-libs/pull/259) Fixes incorrect ordering comparison for IFP64, IFP128 and IFP256. #### Breaking From 92d8f4bc317586dcf6fb4ee1d96dd5e600d3cbb4 Mon Sep 17 00:00:00 2001 From: SwayStar123 Date: Wed, 3 Jul 2024 08:03:57 +0000 Subject: [PATCH 4/9] add more tests --- libs/src/fixed_point/ifp128.sw | 56 +++++++++++++++++++++++++++++++++- libs/src/fixed_point/ifp256.sw | 56 +++++++++++++++++++++++++++++++++- libs/src/fixed_point/ifp64.sw | 54 ++++++++++++++++++++++++++++++++ 3 files changed, 164 insertions(+), 2 deletions(-) diff --git a/libs/src/fixed_point/ifp128.sw b/libs/src/fixed_point/ifp128.sw index 6a2c3504..48f5a770 100644 --- a/libs/src/fixed_point/ifp128.sw +++ b/libs/src/fixed_point/ifp128.sw @@ -571,9 +571,63 @@ impl Power for IFP128 { #[test] fn test_ord() { + let num = IFP128::min(); + let num2 = IFP128::min(); + + assert(!(num > num2)); + assert(!(num < num2)); + assert(!(num2 < num)); + assert(!(num2 > num)); + + let num = IFP128::min(); + let num2 = IFP128::from_uint(42_u64); + + assert(num < num2); + assert(num2 > num); + + let num = IFP128::min(); + let num2 = IFP128::max(); + + assert(num < num2); + assert(num2 > num); + let num = IFP128::from_uint(42_u64); let num2 = IFP128::min(); assert(num > num2); assert(num2 < num); -} + + let num = IFP128::from_uint(42_u64); + let num2 = IFP128::from_uint(42_u64); + + assert(!(num > num2)); + assert(!(num < num2)); + assert(!(num2 < num)); + assert(!(num2 > num)); + + let num = IFP128::from_uint(42_u64); + let num2 = IFP128::max(); + + assert(num < num2); + assert(num2 > num); + + let num = IFP128::max(); + let num2 = IFP128::min(); + + assert(num > num2); + assert(num2 < num); + + let num = IFP128::max(); + let num2 = IFP128::from_uint(42_u64); + + assert(num > num2); + assert(num2 < num); + + let num = IFP128::max(); + let num2 = IFP128::max(); + + assert(!(num > num2)); + assert(!(num < num2)); + assert(!(num2 < num)); + assert(!(num2 > num)); +} \ No newline at end of file diff --git a/libs/src/fixed_point/ifp256.sw b/libs/src/fixed_point/ifp256.sw index 46abb609..66f0573e 100644 --- a/libs/src/fixed_point/ifp256.sw +++ b/libs/src/fixed_point/ifp256.sw @@ -571,9 +571,63 @@ impl Power for IFP256 { #[test] fn test_ord() { + let num = IFP256::min(); + let num2 = IFP256::min(); + + assert(!(num > num2)); + assert(!(num < num2)); + assert(!(num2 < num)); + assert(!(num2 > num)); + + let num = IFP256::min(); + let num2 = IFP256::from_uint(42_u64); + + assert(num < num2); + assert(num2 > num); + + let num = IFP256::min(); + let num2 = IFP256::max(); + + assert(num < num2); + assert(num2 > num); + let num = IFP256::from_uint(42_u64); let num2 = IFP256::min(); assert(num > num2); assert(num2 < num); -} + + let num = IFP256::from_uint(42_u64); + let num2 = IFP256::from_uint(42_u64); + + assert(!(num > num2)); + assert(!(num < num2)); + assert(!(num2 < num)); + assert(!(num2 > num)); + + let num = IFP256::from_uint(42_u64); + let num2 = IFP256::max(); + + assert(num < num2); + assert(num2 > num); + + let num = IFP256::max(); + let num2 = IFP256::min(); + + assert(num > num2); + assert(num2 < num); + + let num = IFP256::max(); + let num2 = IFP256::from_uint(42_u64); + + assert(num > num2); + assert(num2 < num); + + let num = IFP256::max(); + let num2 = IFP256::max(); + + assert(!(num > num2)); + assert(!(num < num2)); + assert(!(num2 < num)); + assert(!(num2 > num)); +} \ No newline at end of file diff --git a/libs/src/fixed_point/ifp64.sw b/libs/src/fixed_point/ifp64.sw index 5700b7b0..eb234855 100644 --- a/libs/src/fixed_point/ifp64.sw +++ b/libs/src/fixed_point/ifp64.sw @@ -571,9 +571,63 @@ impl Power for IFP64 { #[test] fn test_ord() { + let num = IFP64::min(); + let num2 = IFP64::min(); + + assert(!(num > num2)); + assert(!(num < num2)); + assert(!(num2 < num)); + assert(!(num2 > num)); + + let num = IFP64::min(); + let num2 = IFP64::from_uint(42_u32); + + assert(num < num2); + assert(num2 > num); + + let num = IFP64::min(); + let num2 = IFP64::max(); + + assert(num < num2); + assert(num2 > num); + + let num = IFP64::from_uint(42_u32); + let num2 = IFP64::min(); + + assert(num > num2); + assert(num2 < num); + + let num = IFP64::from_uint(42_u32); + let num2 = IFP64::from_uint(42_u32); + + assert(!(num > num2)); + assert(!(num < num2)); + assert(!(num2 < num)); + assert(!(num2 > num)); + let num = IFP64::from_uint(42_u32); + let num2 = IFP64::max(); + + assert(num < num2); + assert(num2 > num); + + let num = IFP64::max(); let num2 = IFP64::min(); assert(num > num2); assert(num2 < num); + + let num = IFP64::max(); + let num2 = IFP64::from_uint(42_u32); + + assert(num > num2); + assert(num2 < num); + + let num = IFP64::max(); + let num2 = IFP64::max(); + + assert(!(num > num2)); + assert(!(num < num2)); + assert(!(num2 < num)); + assert(!(num2 > num)); } From 24d38a1b9442db0a8f2450ad1d61b7e226040c2a Mon Sep 17 00:00:00 2001 From: SwayStar123 Date: Fri, 5 Jul 2024 11:52:48 +0530 Subject: [PATCH 5/9] fix pr number --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed0cf25b..95ad6b18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ Description of the upcoming release here. ### Fixed - [#258](https://github.com/FuelLabs/sway-libs/pull/258) Fixes incorrect intructions on how to run tests in README and docs hub. -- [#259](https://github.com/FuelLabs/sway-libs/pull/259) Fixes incorrect ordering comparison for IFP64, IFP128 and IFP256. +- [#262](https://github.com/FuelLabs/sway-libs/pull/262) Fixes incorrect ordering comparison for IFP64, IFP128 and IFP256. #### Breaking From d56973b99f523eee16ec17d355917a41205cc0c4 Mon Sep 17 00:00:00 2001 From: SwayStar123 Date: Sat, 6 Jul 2024 13:18:08 +0530 Subject: [PATCH 6/9] fmt --- libs/src/fixed_point/ifp128.sw | 2 +- libs/src/fixed_point/ifp256.sw | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/src/fixed_point/ifp128.sw b/libs/src/fixed_point/ifp128.sw index 48f5a770..30e0895e 100644 --- a/libs/src/fixed_point/ifp128.sw +++ b/libs/src/fixed_point/ifp128.sw @@ -630,4 +630,4 @@ fn test_ord() { assert(!(num < num2)); assert(!(num2 < num)); assert(!(num2 > num)); -} \ No newline at end of file +} diff --git a/libs/src/fixed_point/ifp256.sw b/libs/src/fixed_point/ifp256.sw index 66f0573e..356d2fca 100644 --- a/libs/src/fixed_point/ifp256.sw +++ b/libs/src/fixed_point/ifp256.sw @@ -630,4 +630,4 @@ fn test_ord() { assert(!(num < num2)); assert(!(num2 < num)); assert(!(num2 > num)); -} \ No newline at end of file +} From e2a66d7e5de150f7c75ebba476bc1b301c758cf6 Mon Sep 17 00:00:00 2001 From: SwayStar123 Date: Wed, 10 Jul 2024 11:28:26 +0530 Subject: [PATCH 7/9] move tests to test script in tests folder --- libs/src/fixed_point/ifp128.sw | 63 ------------------- libs/src/fixed_point/ifp256.sw | 63 ------------------- libs/src/fixed_point/ifp64.sw | 63 ------------------- tests/src/fixed_point/ifp128_test/src/main.sw | 61 ++++++++++++++++++ tests/src/fixed_point/ifp256_test/src/main.sw | 61 ++++++++++++++++++ tests/src/fixed_point/ifp64_test/src/main.sw | 61 ++++++++++++++++++ 6 files changed, 183 insertions(+), 189 deletions(-) diff --git a/libs/src/fixed_point/ifp128.sw b/libs/src/fixed_point/ifp128.sw index 30e0895e..3a25a68b 100644 --- a/libs/src/fixed_point/ifp128.sw +++ b/libs/src/fixed_point/ifp128.sw @@ -568,66 +568,3 @@ impl Power for IFP128 { } } } - -#[test] -fn test_ord() { - let num = IFP128::min(); - let num2 = IFP128::min(); - - assert(!(num > num2)); - assert(!(num < num2)); - assert(!(num2 < num)); - assert(!(num2 > num)); - - let num = IFP128::min(); - let num2 = IFP128::from_uint(42_u64); - - assert(num < num2); - assert(num2 > num); - - let num = IFP128::min(); - let num2 = IFP128::max(); - - assert(num < num2); - assert(num2 > num); - - let num = IFP128::from_uint(42_u64); - let num2 = IFP128::min(); - - assert(num > num2); - assert(num2 < num); - - let num = IFP128::from_uint(42_u64); - let num2 = IFP128::from_uint(42_u64); - - assert(!(num > num2)); - assert(!(num < num2)); - assert(!(num2 < num)); - assert(!(num2 > num)); - - let num = IFP128::from_uint(42_u64); - let num2 = IFP128::max(); - - assert(num < num2); - assert(num2 > num); - - let num = IFP128::max(); - let num2 = IFP128::min(); - - assert(num > num2); - assert(num2 < num); - - let num = IFP128::max(); - let num2 = IFP128::from_uint(42_u64); - - assert(num > num2); - assert(num2 < num); - - let num = IFP128::max(); - let num2 = IFP128::max(); - - assert(!(num > num2)); - assert(!(num < num2)); - assert(!(num2 < num)); - assert(!(num2 > num)); -} diff --git a/libs/src/fixed_point/ifp256.sw b/libs/src/fixed_point/ifp256.sw index 356d2fca..b68c005c 100644 --- a/libs/src/fixed_point/ifp256.sw +++ b/libs/src/fixed_point/ifp256.sw @@ -568,66 +568,3 @@ impl Power for IFP256 { } } } - -#[test] -fn test_ord() { - let num = IFP256::min(); - let num2 = IFP256::min(); - - assert(!(num > num2)); - assert(!(num < num2)); - assert(!(num2 < num)); - assert(!(num2 > num)); - - let num = IFP256::min(); - let num2 = IFP256::from_uint(42_u64); - - assert(num < num2); - assert(num2 > num); - - let num = IFP256::min(); - let num2 = IFP256::max(); - - assert(num < num2); - assert(num2 > num); - - let num = IFP256::from_uint(42_u64); - let num2 = IFP256::min(); - - assert(num > num2); - assert(num2 < num); - - let num = IFP256::from_uint(42_u64); - let num2 = IFP256::from_uint(42_u64); - - assert(!(num > num2)); - assert(!(num < num2)); - assert(!(num2 < num)); - assert(!(num2 > num)); - - let num = IFP256::from_uint(42_u64); - let num2 = IFP256::max(); - - assert(num < num2); - assert(num2 > num); - - let num = IFP256::max(); - let num2 = IFP256::min(); - - assert(num > num2); - assert(num2 < num); - - let num = IFP256::max(); - let num2 = IFP256::from_uint(42_u64); - - assert(num > num2); - assert(num2 < num); - - let num = IFP256::max(); - let num2 = IFP256::max(); - - assert(!(num > num2)); - assert(!(num < num2)); - assert(!(num2 < num)); - assert(!(num2 > num)); -} diff --git a/libs/src/fixed_point/ifp64.sw b/libs/src/fixed_point/ifp64.sw index eb234855..63d03b97 100644 --- a/libs/src/fixed_point/ifp64.sw +++ b/libs/src/fixed_point/ifp64.sw @@ -568,66 +568,3 @@ impl Power for IFP64 { } } } - -#[test] -fn test_ord() { - let num = IFP64::min(); - let num2 = IFP64::min(); - - assert(!(num > num2)); - assert(!(num < num2)); - assert(!(num2 < num)); - assert(!(num2 > num)); - - let num = IFP64::min(); - let num2 = IFP64::from_uint(42_u32); - - assert(num < num2); - assert(num2 > num); - - let num = IFP64::min(); - let num2 = IFP64::max(); - - assert(num < num2); - assert(num2 > num); - - let num = IFP64::from_uint(42_u32); - let num2 = IFP64::min(); - - assert(num > num2); - assert(num2 < num); - - let num = IFP64::from_uint(42_u32); - let num2 = IFP64::from_uint(42_u32); - - assert(!(num > num2)); - assert(!(num < num2)); - assert(!(num2 < num)); - assert(!(num2 > num)); - - let num = IFP64::from_uint(42_u32); - let num2 = IFP64::max(); - - assert(num < num2); - assert(num2 > num); - - let num = IFP64::max(); - let num2 = IFP64::min(); - - assert(num > num2); - assert(num2 < num); - - let num = IFP64::max(); - let num2 = IFP64::from_uint(42_u32); - - assert(num > num2); - assert(num2 < num); - - let num = IFP64::max(); - let num2 = IFP64::max(); - - assert(!(num > num2)); - assert(!(num < num2)); - assert(!(num2 < num)); - assert(!(num2 > num)); -} diff --git a/tests/src/fixed_point/ifp128_test/src/main.sw b/tests/src/fixed_point/ifp128_test/src/main.sw index 798b155a..9e42c152 100644 --- a/tests/src/fixed_point/ifp128_test/src/main.sw +++ b/tests/src/fixed_point/ifp128_test/src/main.sw @@ -65,5 +65,66 @@ fn main() -> bool { res = value.round(); assert(IFP128::from_uint(2) == res); + // Ord tests + let num = IFP128::min(); + let num2 = IFP128::min(); + + assert(!(num > num2)); + assert(!(num < num2)); + assert(!(num2 < num)); + assert(!(num2 > num)); + + let num = IFP128::min(); + let num2 = IFP128::from_uint(42_u64); + + assert(num < num2); + assert(num2 > num); + + let num = IFP128::min(); + let num2 = IFP128::max(); + + assert(num < num2); + assert(num2 > num); + + let num = IFP128::from_uint(42_u64); + let num2 = IFP128::min(); + + assert(num > num2); + assert(num2 < num); + + let num = IFP128::from_uint(42_u64); + let num2 = IFP128::from_uint(42_u64); + + assert(!(num > num2)); + assert(!(num < num2)); + assert(!(num2 < num)); + assert(!(num2 > num)); + + let num = IFP128::from_uint(42_u64); + let num2 = IFP128::max(); + + assert(num < num2); + assert(num2 > num); + + let num = IFP128::max(); + let num2 = IFP128::min(); + + assert(num > num2); + assert(num2 < num); + + let num = IFP128::max(); + let num2 = IFP128::from_uint(42_u64); + + assert(num > num2); + assert(num2 < num); + + let num = IFP128::max(); + let num2 = IFP128::max(); + + assert(!(num > num2)); + assert(!(num < num2)); + assert(!(num2 < num)); + assert(!(num2 > num)); + true } diff --git a/tests/src/fixed_point/ifp256_test/src/main.sw b/tests/src/fixed_point/ifp256_test/src/main.sw index 88c8edcc..ef329aaa 100644 --- a/tests/src/fixed_point/ifp256_test/src/main.sw +++ b/tests/src/fixed_point/ifp256_test/src/main.sw @@ -65,5 +65,66 @@ fn main() -> bool { res = value.round(); assert(IFP256::from_uint(2) == res); + // Ord tests + let num = IFP256::min(); + let num2 = IFP256::min(); + + assert(!(num > num2)); + assert(!(num < num2)); + assert(!(num2 < num)); + assert(!(num2 > num)); + + let num = IFP256::min(); + let num2 = IFP256::from_uint(42_u64); + + assert(num < num2); + assert(num2 > num); + + let num = IFP256::min(); + let num2 = IFP256::max(); + + assert(num < num2); + assert(num2 > num); + + let num = IFP256::from_uint(42_u64); + let num2 = IFP256::min(); + + assert(num > num2); + assert(num2 < num); + + let num = IFP256::from_uint(42_u64); + let num2 = IFP256::from_uint(42_u64); + + assert(!(num > num2)); + assert(!(num < num2)); + assert(!(num2 < num)); + assert(!(num2 > num)); + + let num = IFP256::from_uint(42_u64); + let num2 = IFP256::max(); + + assert(num < num2); + assert(num2 > num); + + let num = IFP256::max(); + let num2 = IFP256::min(); + + assert(num > num2); + assert(num2 < num); + + let num = IFP256::max(); + let num2 = IFP256::from_uint(42_u64); + + assert(num > num2); + assert(num2 < num); + + let num = IFP256::max(); + let num2 = IFP256::max(); + + assert(!(num > num2)); + assert(!(num < num2)); + assert(!(num2 < num)); + assert(!(num2 > num)); + true } diff --git a/tests/src/fixed_point/ifp64_test/src/main.sw b/tests/src/fixed_point/ifp64_test/src/main.sw index 48a85d3e..4e4b1744 100644 --- a/tests/src/fixed_point/ifp64_test/src/main.sw +++ b/tests/src/fixed_point/ifp64_test/src/main.sw @@ -80,5 +80,66 @@ fn main() -> bool { res = value.round(); assert(IFP64::from_uint(2u32) == res); + // Ord tests + let num = IFP64::min(); + let num2 = IFP64::min(); + + assert(!(num > num2)); + assert(!(num < num2)); + assert(!(num2 < num)); + assert(!(num2 > num)); + + let num = IFP64::min(); + let num2 = IFP64::from_uint(42_u32); + + assert(num < num2); + assert(num2 > num); + + let num = IFP64::min(); + let num2 = IFP64::max(); + + assert(num < num2); + assert(num2 > num); + + let num = IFP64::from_uint(42_u32); + let num2 = IFP64::min(); + + assert(num > num2); + assert(num2 < num); + + let num = IFP64::from_uint(42_u32); + let num2 = IFP64::from_uint(42_u32); + + assert(!(num > num2)); + assert(!(num < num2)); + assert(!(num2 < num)); + assert(!(num2 > num)); + + let num = IFP64::from_uint(42_u32); + let num2 = IFP64::max(); + + assert(num < num2); + assert(num2 > num); + + let num = IFP64::max(); + let num2 = IFP64::min(); + + assert(num > num2); + assert(num2 < num); + + let num = IFP64::max(); + let num2 = IFP64::from_uint(42_u32); + + assert(num > num2); + assert(num2 < num); + + let num = IFP64::max(); + let num2 = IFP64::max(); + + assert(!(num > num2)); + assert(!(num < num2)); + assert(!(num2 < num)); + assert(!(num2 > num)); + true } From c6b0f3742c27930bbda381ea0bad890e1a5cd6be Mon Sep 17 00:00:00 2001 From: SwayStar123 Date: Wed, 10 Jul 2024 11:33:55 +0530 Subject: [PATCH 8/9] fix typo in changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95ad6b18..1d3145ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,7 @@ Description of the upcoming release here. ### Fixed -- [#258](https://github.com/FuelLabs/sway-libs/pull/258) Fixes incorrect intructions on how to run tests in README and docs hub. +- [#258](https://github.com/FuelLabs/sway-libs/pull/258) Fixes incorrect instructions on how to run tests in README and docs hub. - [#262](https://github.com/FuelLabs/sway-libs/pull/262) Fixes incorrect ordering comparison for IFP64, IFP128 and IFP256. #### Breaking From f0bbc449836a38b206544e6ef77dc62929bee965 Mon Sep 17 00:00:00 2001 From: SwayStar123 Date: Tue, 16 Jul 2024 20:05:52 +0530 Subject: [PATCH 9/9] empty commit