Skip to content

Commit 3ad4b80

Browse files
committed
Add more doctests for saturating_shl
1 parent 78c4b4f commit 3ad4b80

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

library/core/src/num/int_macros.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1002,9 +1002,12 @@ macro_rules! int_impl {
10021002
///
10031003
/// ```
10041004
/// #![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);")]
10051007
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".saturating_shl(", stringify!($SelfT), "::BITS), 0);")]
10061008
#[doc = concat!("assert_eq!(1_", stringify!($SelfT), ".saturating_shl(", stringify!($SelfT), "::BITS - 2), 1_", stringify!($SelfT), " << ", stringify!($SelfT), "::BITS - 2);")]
10071009
#[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);")]
10081011
#[doc = concat!("assert_eq!(-1_", stringify!($SelfT), ".saturating_shl(", stringify!($SelfT), "::BITS - 2), -1_", stringify!($SelfT), " << ", stringify!($SelfT), "::BITS - 2);")]
10091012
#[doc = concat!("assert_eq!(-1_", stringify!($SelfT), ".saturating_shl(", stringify!($SelfT), "::BITS - 1), ", stringify!($SelfT), "::MIN);")]
10101013
#[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 {
10181021
if rhs == 0 {
10191022
self
10201023
} else {
1021-
// leading zeros ignoring first bit (which indicates negative values)
1024+
// leading zeros/ones but ignoring first bit (which indicates negative values)
10221025
let leading_zeros = (self << 1).leading_zeros();
10231026
let leading_ones = (self << 1).leading_ones();
10241027

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
10261029
if self > 0 && leading_zeros < rhs {
10271030
Self::MAX
10281031
} else if self < 0 && leading_ones < rhs {

0 commit comments

Comments
 (0)