-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Implement feature isolate_most_least_significant_one
for integer types
#136910
Conversation
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.
Mind implementing some tests?
Implement accepted ACP for functions that isolate the most significant set bit and least significant set bit on unsigned, signed, and NonZero integers. Add function `isolate_most_significant_one` Add function `isolate_least_significant_one` Add tests
I wasn't sure of what kinds of tests to add. Added tests for ints, uints, and NonZero which start with // Right shift each loop
Bits : 0b1111 | 0b0111 | 0b0011 | 0b0001
Most Sig One : 0b1000 | 0b0100 | 0b0010 | 0b0001
// Left shift each loop
Bits : 0b1111 | 0b1110 | 0b1100 | 0b1000
Least Sig One: 0b0001 | 0b0010 | 0b0100 | 0b1000 @rustbot label -S-waiting-on-author +S-waiting-on-review |
Thanks! @bors r+ |
Implement feature `isolate_most_least_significant_one` for integer types Accepted ACP - rust-lang/libs-team#467 Tracking issue - rust-lang#136909 Implement ACP for functions that isolate the most significant set bit and least significant set bit on unsigned, signed, and `NonZero` integers. Add function `isolate_most_significant_one` Add function `isolate_least_significant_one` --- This PR adds the following impls ```rust impl {u8, u16, u32, u64, u128, usize} { const fn isolate_most_significant_one(self) -> Self; const fn isolate_least_significant_one(self) -> Self; } impl {i8, i16, i32, i64, i128, isize} { const fn isolate_most_significant_one(self) -> Self; const fn isolate_least_significant_one(self) -> Self; } impl NonZeroT { const fn isolate_most_significant_one(self) -> Self; const fn isolate_least_significant_one(self) -> Self; } ``` Example behavior ```rust assert_eq!(u8::isolate_most_significant_one(0b01100100), 0b01000000); assert_eq!(u8::isolate_least_significant_one(0b01100100), 0b00000100); ```
…mpiler-errors Rollup of 10 pull requests Successful merges: - rust-lang#136642 (Put the alloc unit tests in a separate alloctests package) - rust-lang#136910 (Implement feature `isolate_most_least_significant_one` for integer types) - rust-lang#137183 (Prune dead regionck code) - rust-lang#137333 (Use `edition = "2024"` in the compiler (redux)) - rust-lang#137356 (Ferris 🦀 Identifier naming conventions) - rust-lang#137362 (Add build step log for `run-make-support`) - rust-lang#137377 (Always allow reusing cratenum in CrateLoader::load) - rust-lang#137388 (Fix(lib/fs/tests): Disable rename POSIX semantics FS tests under Windows 7) - rust-lang#137410 (Use StableHasher + Hash64 for dep_tracking_hash) - rust-lang#137413 (jubilee cleared out the review queue) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#136910 (Implement feature `isolate_most_least_significant_one` for integer types) - rust-lang#137183 (Prune dead regionck code) - rust-lang#137333 (Use `edition = "2024"` in the compiler (redux)) - rust-lang#137356 (Ferris 🦀 Identifier naming conventions) - rust-lang#137362 (Add build step log for `run-make-support`) - rust-lang#137377 (Always allow reusing cratenum in CrateLoader::load) - rust-lang#137388 (Fix(lib/fs/tests): Disable rename POSIX semantics FS tests under Windows 7) - rust-lang#137410 (Use StableHasher + Hash64 for dep_tracking_hash) - rust-lang#137413 (jubilee cleared out the review queue) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#136910 - okaneco:sig_ones, r=thomcc Implement feature `isolate_most_least_significant_one` for integer types Accepted ACP - rust-lang/libs-team#467 Tracking issue - rust-lang#136909 Implement ACP for functions that isolate the most significant set bit and least significant set bit on unsigned, signed, and `NonZero` integers. Add function `isolate_most_significant_one` Add function `isolate_least_significant_one` --- This PR adds the following impls ```rust impl {u8, u16, u32, u64, u128, usize} { const fn isolate_most_significant_one(self) -> Self; const fn isolate_least_significant_one(self) -> Self; } impl {i8, i16, i32, i64, i128, isize} { const fn isolate_most_significant_one(self) -> Self; const fn isolate_least_significant_one(self) -> Self; } impl NonZeroT { const fn isolate_most_significant_one(self) -> Self; const fn isolate_least_significant_one(self) -> Self; } ``` Example behavior ```rust assert_eq!(u8::isolate_most_significant_one(0b01100100), 0b01000000); assert_eq!(u8::isolate_least_significant_one(0b01100100), 0b00000100); ```
Accepted ACP - rust-lang/libs-team#467
Tracking issue - #136909
Implement ACP for functions that isolate the most significant set bit and least significant set bit on unsigned, signed, and
NonZero
integers.Add function
isolate_most_significant_one
Add function
isolate_least_significant_one
This PR adds the following impls
Example behavior