@@ -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 {
@@ -147,6 +156,7 @@ impl ConstChoice {
147156}
148157
149158impl From < ConstChoice > for Choice {
159+ #[ inline]
150160 fn from ( choice : ConstChoice ) -> Self {
151161 Choice :: from ( choice. to_u8 ( ) )
152162 }
@@ -169,6 +179,20 @@ mod tests {
169179 use super :: ConstChoice ;
170180 use crate :: Word ;
171181
182+ #[ test]
183+ fn from_word_lt ( ) {
184+ assert_eq ! ( ConstChoice :: from_word_lt( 4 , 5 ) , ConstChoice :: TRUE ) ;
185+ assert_eq ! ( ConstChoice :: from_word_lt( 5 , 5 ) , ConstChoice :: FALSE ) ;
186+ assert_eq ! ( ConstChoice :: from_word_lt( 6 , 5 ) , ConstChoice :: FALSE ) ;
187+ }
188+
189+ #[ test]
190+ fn from_word_gt ( ) {
191+ assert_eq ! ( ConstChoice :: from_word_gt( 4 , 5 ) , ConstChoice :: FALSE ) ;
192+ assert_eq ! ( ConstChoice :: from_word_gt( 5 , 5 ) , ConstChoice :: FALSE ) ;
193+ assert_eq ! ( ConstChoice :: from_word_gt( 6 , 5 ) , ConstChoice :: TRUE ) ;
194+ }
195+
172196 #[ test]
173197 fn select ( ) {
174198 let a: Word = 1 ;
0 commit comments