@@ -2288,6 +2288,13 @@ macro_rules! int_impl {
22882288 /// Panic-free bitwise shift-left; yields `self << mask(rhs)`, where `mask` removes
22892289 /// any high-order bits of `rhs` that would cause the shift to exceed the bitwidth of the type.
22902290 ///
2291+ /// Beware that, unlike most other `wrapping_*` methods on integers, this
2292+ /// does *not* give the same result as doing the shift in infinite precision
2293+ /// then truncating as needed. The behaviour matches what shift instructions
2294+ /// do on many processors, and is what the `<<` operator does when overflow
2295+ /// checks are disabled, but numerically it's weird. Consider, instead,
2296+ /// using [`Self::unbounded_shl`] which has nicer behaviour.
2297+ ///
22912298 /// Note that this is *not* the same as a rotate-left; the RHS of a wrapping shift-left is restricted to
22922299 /// the range of the type, rather than the bits shifted out of the LHS being returned to the other end.
22932300 /// The primitive integer types all implement a [`rotate_left`](Self::rotate_left) function,
@@ -2296,8 +2303,10 @@ macro_rules! int_impl {
22962303 /// # Examples
22972304 ///
22982305 /// ```
2299- #[ doc = concat!( "assert_eq!((-1" , stringify!( $SelfT) , ").wrapping_shl(7), -128);" ) ]
2300- #[ doc = concat!( "assert_eq!((-1" , stringify!( $SelfT) , ").wrapping_shl(128), -1);" ) ]
2306+ #[ doc = concat!( "assert_eq!((-1_" , stringify!( $SelfT) , ").wrapping_shl(7), -128);" ) ]
2307+ #[ doc = concat!( "assert_eq!(42_" , stringify!( $SelfT) , ".wrapping_shl(" , stringify!( $SelfT) , "::BITS), 42);" ) ]
2308+ #[ doc = concat!( "assert_eq!((-1_" , stringify!( $SelfT) , ").wrapping_shl(128), -1);" ) ]
2309+ #[ doc = concat!( "assert_eq!(5_" , stringify!( $SelfT) , ".wrapping_shl(1025), 10);" ) ]
23012310 /// ```
23022311 #[ stable( feature = "num_wrapping" , since = "1.2.0" ) ]
23032312 #[ rustc_const_stable( feature = "const_int_methods" , since = "1.32.0" ) ]
@@ -2315,6 +2324,13 @@ macro_rules! int_impl {
23152324 /// Panic-free bitwise shift-right; yields `self >> mask(rhs)`, where `mask`
23162325 /// removes any high-order bits of `rhs` that would cause the shift to exceed the bitwidth of the type.
23172326 ///
2327+ /// Beware that, unlike most other `wrapping_*` methods on integers, this
2328+ /// does *not* give the same result as doing the shift in infinite precision
2329+ /// then truncating as needed. The behaviour matches what shift instructions
2330+ /// do on many processors, and is what the `>>` operator does when overflow
2331+ /// checks are disabled, but numerically it's weird. Consider, instead,
2332+ /// using [`Self::unbounded_shr`] which has nicer behaviour.
2333+ ///
23182334 /// Note that this is *not* the same as a rotate-right; the RHS of a wrapping shift-right is restricted
23192335 /// to the range of the type, rather than the bits shifted out of the LHS being returned to the other
23202336 /// end. The primitive integer types all implement a [`rotate_right`](Self::rotate_right) function,
@@ -2323,8 +2339,10 @@ macro_rules! int_impl {
23232339 /// # Examples
23242340 ///
23252341 /// ```
2326- #[ doc = concat!( "assert_eq!((-128" , stringify!( $SelfT) , ").wrapping_shr(7), -1);" ) ]
2327- /// assert_eq!((-128i16).wrapping_shr(64), -128);
2342+ #[ doc = concat!( "assert_eq!((-128_" , stringify!( $SelfT) , ").wrapping_shr(7), -1);" ) ]
2343+ #[ doc = concat!( "assert_eq!(42_" , stringify!( $SelfT) , ".wrapping_shr(" , stringify!( $SelfT) , "::BITS), 42);" ) ]
2344+ /// assert_eq!((-128_i16).wrapping_shr(64), -128);
2345+ #[ doc = concat!( "assert_eq!(10_" , stringify!( $SelfT) , ".wrapping_shr(1025), 5);" ) ]
23282346 /// ```
23292347 #[ stable( feature = "num_wrapping" , since = "1.2.0" ) ]
23302348 #[ rustc_const_stable( feature = "const_int_methods" , since = "1.32.0" ) ]
0 commit comments