-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add log2
and log10
to NonZeroU*
#92956
Conversation
This version is nice in that it doesn't need to worry about zeros, and thus doesn't have any error cases.
r? @yaahc (rust-highfive has picked a reviewer for you, use r? to override) |
pub const fn u8(val: u8) -> u32 { | ||
let val = val as u32; | ||
|
||
// For better performance, avoid branches by assembling the solution |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are unchanged, just de-indented. You might want to use ignore whitespace mode to review.
} else { | ||
// SAFETY: We just checked that this number is positive | ||
let log = (Self::BITS - 1) - unsafe { intrinsics::ctlz_nonzero(self) as u32 }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One fewer unsafe
, as a bonus.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
@bors r+ |
📌 Commit 3dfcc66 has been approved by |
…askrgr Rollup of 10 pull requests Successful merges: - rust-lang#90498 (Clarifications in the target tier policy) - rust-lang#92164 (Implement `#[rustc_must_implement_one_of]` attribute) - rust-lang#92729 (rustc_codegen_llvm: Remove (almost) unused span parameter from many functions in metadata.rs) - rust-lang#92752 (Correct minor typos in some long error code explanations) - rust-lang#92801 (Enable wrapping words by default) - rust-lang#92825 (Rename environment variable for overriding rustc version) - rust-lang#92877 (Remove LLVMRustMarkAllFunctionsNounwind) - rust-lang#92936 (rustdoc: Remove `collect` in `html::markdown::parse`) - rust-lang#92956 (Add `log2` and `log10` to `NonZeroU*`) - rust-lang#92960 (Use `carrying_{mul|add}` in `num::bignum`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This version is nice in that it doesn't need to worry about zeros, and thus doesn't have any error cases.
cc
int_log
tracking issue #70887(I didn't add them to
NonZeroI*
despite it being oni*
since allowing negatives bring back the error cases again.)