@@ -1002,9 +1002,12 @@ macro_rules! int_impl {
1002
1002
///
1003
1003
/// ```
1004
1004
/// #![feature(saturating_bit_shifts)]
1005
+ #[ doc = concat!( "assert_eq!(42_" , stringify!( $SelfT) , ".saturating_shl(0), 42);" ) ]
1006
+ #[ doc = concat!( "assert_eq!(0_" , stringify!( $SelfT) , ".saturating_shl(1), 0);" ) ]
1005
1007
#[ doc = concat!( "assert_eq!(0_" , stringify!( $SelfT) , ".saturating_shl(" , stringify!( $SelfT) , "::BITS), 0);" ) ]
1006
1008
#[ doc = concat!( "assert_eq!(1_" , stringify!( $SelfT) , ".saturating_shl(" , stringify!( $SelfT) , "::BITS - 2), 1_" , stringify!( $SelfT) , " << " , stringify!( $SelfT) , "::BITS - 2);" ) ]
1007
1009
#[ doc = concat!( "assert_eq!(1_" , stringify!( $SelfT) , ".saturating_shl(" , stringify!( $SelfT) , "::BITS - 1), " , stringify!( $SelfT) , "::MAX);" ) ]
1010
+ #[ doc = concat!( "assert_eq!(-42_" , stringify!( $SelfT) , ".saturating_shl(0), -42);" ) ]
1008
1011
#[ doc = concat!( "assert_eq!(-1_" , stringify!( $SelfT) , ".saturating_shl(" , stringify!( $SelfT) , "::BITS - 2), -1_" , stringify!( $SelfT) , " << " , stringify!( $SelfT) , "::BITS - 2);" ) ]
1009
1012
#[ doc = concat!( "assert_eq!(-1_" , stringify!( $SelfT) , ".saturating_shl(" , stringify!( $SelfT) , "::BITS - 1), " , stringify!( $SelfT) , "::MIN);" ) ]
1010
1013
#[ doc = concat!( "assert_eq!(-1_" , stringify!( $SelfT) , ".saturating_shl(" , stringify!( $SelfT) , "::BITS), " , stringify!( $SelfT) , "::MIN, \" -1_" , stringify!( $SelfT) , ".saturating_shl(" , stringify!( $SelfT) , "::BITS), " , stringify!( $SelfT) , "::MIN\" );" ) ]
@@ -1018,11 +1021,11 @@ macro_rules! int_impl {
1018
1021
if rhs == 0 {
1019
1022
self
1020
1023
} else {
1021
- // leading zeros ignoring first bit (which indicates negative values)
1024
+ // leading zeros/ones but ignoring first bit (which indicates negative values)
1022
1025
let leading_zeros = ( self << 1 ) . leading_zeros( ) ;
1023
1026
let leading_ones = ( self << 1 ) . leading_ones( ) ;
1024
1027
1025
- // would overflow => MIN / MAX depending on whether the value is negative or not
1028
+ // would overflow? => MIN / MAX depending on whether the value is negative or not
1026
1029
if self > 0 && leading_zeros < rhs {
1027
1030
Self :: MAX
1028
1031
} else if self < 0 && leading_ones < rhs {
0 commit comments