From 722030605222529ee6485bf3473d4b2c8099ef61 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 ff3a721736..b45b202cc7 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);