From a0fcb064c11f7d1de4eb7c3c1897b97f9f5c913a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Mon, 16 Oct 2023 17:39:04 -0400 Subject: [PATCH] refactor: Refine numeric comparison in `prop_lesser` function - add a direct comparison from https://github.com/lurk-lab/lurk-rs/pull/738/ --- src/num.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/num.rs b/src/num.rs index 4dc05d0a3c..09e31ace3d 100644 --- a/src/num.rs +++ b/src/num.rs @@ -472,9 +472,13 @@ mod tests { overflow_boundary -= x2; x1 > overflow_boundary }; + let diff = Num::Scalar(x1 - x2); if !underflow && !overflow { - assert_eq!(a.is_less_than(&b), Num::Scalar(x1 - x2).is_negative()); + assert_eq!(a.is_less_than(&b), diff.is_negative()); } + + let same_sign = !(x1.is_negative() ^ x2.is_negative()); + assert_eq!(a.is_less_than(&b), (same_sign && diff.is_negative()) || (!same_sign && a.is_negative())); }, (Num::U64(x1), Num::Scalar(x2)) if !x2.is_negative() => { assert_eq!(a.is_less_than(&b), Scalar::from(x1) < x2);