Rollup merge of #151274 - count_zeros_note, r=jhpratt
Include a link to `count_ones` in the docs for `uN::count_zeros` [docs only] I did not update `iN` because `count_zeros` is reasonable for *negative* numbers. Rendered: <img width="1188" height="524" alt="image" src="https://github.com/user-attachments/assets/80ebf53c-3cde-4230-b436-d2148b07d4c8" /> <img width="1186" height="517" alt="image" src="https://github.com/user-attachments/assets/544d2ff4-ee35-44f7-8d50-65fc5f0ff3c9" />
This commit is contained in:
commit
0f52e310c1
1 changed files with 22 additions and 0 deletions
|
|
@ -93,6 +93,28 @@ macro_rules! uint_impl {
|
|||
#[doc = concat!("let max = ", stringify!($SelfT),"::MAX;")]
|
||||
/// assert_eq!(max.count_zeros(), 0);
|
||||
/// ```
|
||||
///
|
||||
/// This is heavily dependent on the width of the type, and thus
|
||||
/// might give surprising results depending on type inference:
|
||||
/// ```
|
||||
/// # fn foo(_: u8) {}
|
||||
/// # fn bar(_: u16) {}
|
||||
/// let lucky = 7;
|
||||
/// foo(lucky);
|
||||
/// assert_eq!(lucky.count_zeros(), 5);
|
||||
/// assert_eq!(lucky.count_ones(), 3);
|
||||
///
|
||||
/// let lucky = 7;
|
||||
/// bar(lucky);
|
||||
/// assert_eq!(lucky.count_zeros(), 13);
|
||||
/// assert_eq!(lucky.count_ones(), 3);
|
||||
/// ```
|
||||
/// You might want to use [`Self::count_ones`] instead, or emphasize
|
||||
/// the type you're using in the call rather than method syntax:
|
||||
/// ```
|
||||
/// let small = 1;
|
||||
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::count_zeros(small), ", stringify!($BITS_MINUS_ONE) ,");")]
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_stable(feature = "const_math", since = "1.32.0")]
|
||||
#[must_use = "this returns the result of the operation, \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue