@@ -71,10 +71,19 @@ impl ConstChoice {
7171 /// Returns the truthy value if `x < y`, and the falsy value otherwise.
7272 #[ inline]
7373 pub ( crate ) const fn from_word_lt ( x : Word , y : Word ) -> Self {
74+ // See "Hacker's Delight" 2nd ed, section 2-12 (Comparison predicates)
7475 let bit = ( ( ( !x) & y) | ( ( ( !x) | y) & ( x. wrapping_sub ( y) ) ) ) >> ( Word :: BITS - 1 ) ;
7576 Self :: from_word_lsb ( bit)
7677 }
7778
79+ /// Returns the truthy value if `x > y`, and the falsy value otherwise.
80+ #[ inline]
81+ pub ( crate ) const fn from_word_gt ( x : Word , y : Word ) -> Self {
82+ // See "Hacker's Delight" 2nd ed, section 2-12 (Comparison predicates)
83+ let bit = ( ( ( !y) & x) | ( ( ( !y) | x) & ( y. wrapping_sub ( x) ) ) ) >> ( Word :: BITS - 1 ) ;
84+ Self :: from_word_lsb ( bit)
85+ }
86+
7887 /// Returns the truthy value if `x < y`, and the falsy value otherwise.
7988 #[ inline]
8089 pub ( crate ) const fn from_u32_lt ( x : u32 , y : u32 ) -> Self {
@@ -169,6 +178,20 @@ mod tests {
169178 use super :: ConstChoice ;
170179 use crate :: Word ;
171180
181+ #[ test]
182+ fn from_word_lt ( ) {
183+ assert_eq ! ( ConstChoice :: from_word_lt( 4 , 5 ) , ConstChoice :: TRUE ) ;
184+ assert_eq ! ( ConstChoice :: from_word_lt( 5 , 5 ) , ConstChoice :: FALSE ) ;
185+ assert_eq ! ( ConstChoice :: from_word_lt( 6 , 5 ) , ConstChoice :: FALSE ) ;
186+ }
187+
188+ #[ test]
189+ fn from_word_gt ( ) {
190+ assert_eq ! ( ConstChoice :: from_word_gt( 4 , 5 ) , ConstChoice :: FALSE ) ;
191+ assert_eq ! ( ConstChoice :: from_word_gt( 5 , 5 ) , ConstChoice :: FALSE ) ;
192+ assert_eq ! ( ConstChoice :: from_word_gt( 6 , 5 ) , ConstChoice :: TRUE ) ;
193+ }
194+
172195 #[ test]
173196 fn select ( ) {
174197 let a: Word = 1 ;
0 commit comments