Skip to content
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

Merged
merged 1 commit into from
Jan 18, 2022
Merged

Conversation

scottmcm
Copy link
Member

@scottmcm scottmcm commented Jan 16, 2022

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 on i* since allowing negatives bring back the error cases again.)

This version is nice in that it doesn't need to worry about zeros, and thus doesn't have any error cases.
@rust-highfive
Copy link
Collaborator

r? @yaahc

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 16, 2022
pub const fn u8(val: u8) -> u32 {
let val = val as u32;

// For better performance, avoid branches by assembling the solution
Copy link
Member Author

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 };
Copy link
Member Author

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.

Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@dtolnay
Copy link
Member

dtolnay commented Jan 16, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Jan 16, 2022

📌 Commit 3dfcc66 has been approved by dtolnay

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 16, 2022
@dtolnay dtolnay assigned dtolnay and unassigned yaahc Jan 16, 2022
@dtolnay dtolnay added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Jan 16, 2022
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
@bors bors merged commit 731af70 into rust-lang:master Jan 18, 2022
@rustbot rustbot added this to the 1.60.0 milestone Jan 18, 2022
@scottmcm scottmcm deleted the nonzero-log2 branch January 18, 2022 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants