Add log2 and log10 to NonZeroU*#92956
Merged
bors merged 1 commit intorust-lang:masterfrom Jan 18, 2022
Merged
Conversation
This version is nice in that it doesn't need to worry about zeros, and thus doesn't have any error cases.
Contributor
|
r? @yaahc (rust-highfive has picked a reviewer for you, use r? to override) |
scottmcm
commented
Jan 16, 2022
| pub const fn u8(val: u8) -> u32 { | ||
| let val = val as u32; | ||
|
|
||
| // For better performance, avoid branches by assembling the solution |
Member
Author
There was a problem hiding this comment.
These are unchanged, just de-indented. You might want to use ignore whitespace mode to review.
scottmcm
commented
Jan 16, 2022
| Some(x.log2()) | ||
| } else { | ||
| // SAFETY: We just checked that this number is positive | ||
| let log = (Self::BITS - 1) - unsafe { intrinsics::ctlz_nonzero(self) as u32 }; |
Member
Author
There was a problem hiding this comment.
One fewer unsafe, as a bonus.
Member
|
@bors r+ |
Collaborator
|
📌 Commit 3dfcc66 has been approved by |
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Jan 17, 2022
…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
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This version is nice in that it doesn't need to worry about zeros, and thus doesn't have any error cases.
cc
int_logtracking issue #70887(I didn't add them to
NonZeroI*despite it being oni*since allowing negatives bring back the error cases again.)