@@ -2593,6 +2593,13 @@ macro_rules! uint_impl {
25932593 /// where `mask` removes any high-order bits of `rhs` that
25942594 /// would cause the shift to exceed the bitwidth of the type.
25952595 ///
2596+ /// Beware that, unlike most other `wrapping_*` methods on integers, this
2597+ /// does *not* give the same result as doing the shift in infinite precision
2598+ /// then truncating as needed. The behaviour matches what shift instructions
2599+ /// do on many processors, and is what the `<<` operator does when overflow
2600+ /// checks are disabled, but numerically it's weird. Consider, instead,
2601+ /// using [`Self::unbounded_shl`] which has nicer behaviour.
2602+ ///
25962603 /// Note that this is *not* the same as a rotate-left; the
25972604 /// RHS of a wrapping shift-left is restricted to the range
25982605 /// of the type, rather than the bits shifted out of the LHS
@@ -2603,8 +2610,16 @@ macro_rules! uint_impl {
26032610 /// # Examples
26042611 ///
26052612 /// ```
2606- #[ doc = concat!( "assert_eq!(1" , stringify!( $SelfT) , ".wrapping_shl(7), 128);" ) ]
2607- #[ doc = concat!( "assert_eq!(1" , stringify!( $SelfT) , ".wrapping_shl(128), 1);" ) ]
2613+ #[ doc = concat!( "assert_eq!(1_" , stringify!( $SelfT) , ".wrapping_shl(7), 128);" ) ]
2614+ #[ doc = concat!( "assert_eq!(42_" , stringify!( $SelfT) , ".wrapping_shl(" , stringify!( $SelfT) , "::BITS), 42);" ) ]
2615+ /// assert_eq!(
2616+ #[ doc = concat!( " 42_" , stringify!( $SelfT) ) ]
2617+ #[ doc = concat!( " .wrapping_shl(" , stringify!( $SelfT) , "::BITS / 2)" ) ]
2618+ #[ doc = concat!( " .wrapping_shl(" , stringify!( $SelfT) , "::BITS / 2)," ) ]
2619+ /// 0,
2620+ /// );
2621+ #[ doc = concat!( "assert_eq!(1_" , stringify!( $SelfT) , ".wrapping_shl(128), 1);" ) ]
2622+ #[ doc = concat!( "assert_eq!(5_" , stringify!( $SelfT) , ".wrapping_shl(1025), 10);" ) ]
26082623 /// ```
26092624 #[ stable( feature = "num_wrapping" , since = "1.2.0" ) ]
26102625 #[ rustc_const_stable( feature = "const_wrapping_math" , since = "1.32.0" ) ]
@@ -2623,6 +2638,13 @@ macro_rules! uint_impl {
26232638 /// where `mask` removes any high-order bits of `rhs` that
26242639 /// would cause the shift to exceed the bitwidth of the type.
26252640 ///
2641+ /// Beware that, unlike most other `wrapping_*` methods on integers, this
2642+ /// does *not* give the same result as doing the shift in infinite precision
2643+ /// then truncating as needed. The behaviour matches what shift instructions
2644+ /// do on many processors, and is what the `>>` operator does when overflow
2645+ /// checks are disabled, but numerically it's weird. Consider, instead,
2646+ /// using [`Self::unbounded_shr`] which has nicer behaviour.
2647+ ///
26262648 /// Note that this is *not* the same as a rotate-right; the
26272649 /// RHS of a wrapping shift-right is restricted to the range
26282650 /// of the type, rather than the bits shifted out of the LHS
@@ -2633,8 +2655,10 @@ macro_rules! uint_impl {
26332655 /// # Examples
26342656 ///
26352657 /// ```
2636- #[ doc = concat!( "assert_eq!(128" , stringify!( $SelfT) , ".wrapping_shr(7), 1);" ) ]
2637- #[ doc = concat!( "assert_eq!(128" , stringify!( $SelfT) , ".wrapping_shr(128), 128);" ) ]
2658+ #[ doc = concat!( "assert_eq!(128_" , stringify!( $SelfT) , ".wrapping_shr(7), 1);" ) ]
2659+ #[ doc = concat!( "assert_eq!(42_" , stringify!( $SelfT) , ".wrapping_shr(" , stringify!( $SelfT) , "::BITS), 42);" ) ]
2660+ #[ doc = concat!( "assert_eq!(128_" , stringify!( $SelfT) , ".wrapping_shr(128), 128);" ) ]
2661+ #[ doc = concat!( "assert_eq!(10_" , stringify!( $SelfT) , ".wrapping_shr(1025), 5);" ) ]
26382662 /// ```
26392663 #[ stable( feature = "num_wrapping" , since = "1.2.0" ) ]
26402664 #[ rustc_const_stable( feature = "const_wrapping_math" , since = "1.32.0" ) ]
0 commit comments