diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index c6cbeea5a0ea6..35166c3938ef1 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -329,6 +329,27 @@ $EndFeature, " } } + doc_comment! { + concat!("Returns the number of leading ones in the binary representation of `self`. + +# Examples + +Basic usage: + +``` +", $Feature, "let n = 0b10110011", stringify!($SelfT), "; + +assert_eq!(n.leading_ones(), 1);", +$EndFeature, " +```"), + #[unstable(feature = "leading_ones_trailing_ones", issue = "0")] + #[rustc_const_unstable(feature = "const_int_ops")] + #[inline] + pub const fn leading_ones(self) -> u32 { + (!self as $UnsignedT).leading_zeros() + } + } + doc_comment! { concat!("Returns the number of trailing zeros in the binary representation of `self`. @@ -350,6 +371,27 @@ $EndFeature, " } } + doc_comment! { + concat!("Returns the number of trailing ones in the binary representation of `self`. + +# Examples + +Basic usage: + +``` +", $Feature, "let n = 0b10110011", stringify!($SelfT), "; + +assert_eq!(n.trailing_ones(), 2);", +$EndFeature, " +```"), + #[unstable(feature = "leading_ones_trailing_ones", issue = "0")] + #[rustc_const_unstable(feature = "const_int_ops")] + #[inline] + pub const fn trailing_ones(self) -> u32 { + (!self as $UnsignedT).trailing_zeros() + } + } + doc_comment! { concat!("Shifts the bits to the left by a specified amount, `n`, wrapping the truncated bits to the end of the resulting integer. @@ -2260,6 +2302,26 @@ assert_eq!(n.leading_zeros(), 2);", $EndFeature, " } } + doc_comment! { + concat!("Returns the number of leading ones in the binary representation of `self`. + +# Examples + +Basic usage: + +``` +", $Feature, "let n = 0b11001100", stringify!($SelfT), "; + +assert_eq!(n.leading_ones(), 2);", $EndFeature, " +```"), + #[unstable(feature = "leading_ones_trailing_ones", issue = "0")] + #[rustc_const_unstable(feature = "const_int_ops")] + #[inline] + pub const fn leading_ones(self) -> u32 { + (!self).leading_zeros() + } + } + doc_comment! { concat!("Returns the number of trailing zeros in the binary representation of `self`. @@ -2281,6 +2343,27 @@ assert_eq!(n.trailing_zeros(), 3);", $EndFeature, " } } + doc_comment! { + concat!("Returns the number of trailing ones in the binary representation +of `self`. + +# Examples + +Basic usage: + +``` +", $Feature, "let n = 0b0101011", stringify!($SelfT), "; + +assert_eq!(n.trailing_ones(), 2);", $EndFeature, " +```"), + #[unstable(feature = "leading_ones_trailing_ones", issue = "0")] + #[rustc_const_unstable(feature = "const_int_ops")] + #[inline] + pub const fn trailing_ones(self) -> u32 { + (!self).trailing_zeros() + } + } + doc_comment! { concat!("Shifts the bits to the left by a specified amount, `n`, wrapping the truncated bits to the end of the resulting integer.