-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Description
Feature gate: #![feature(isolate_most_least_significant_one)]
This is a tracking issue for functions that return an integer with only the most significant set bit or only the least significant set bit masked from the input integer.
The functions are implemented for unsigned, signed, and NonZeroT
integer types.
Public API
impl {u8, u16, u32, u64, u128, usize} {
const fn isolate_highest_one(self) -> Self;
const fn isolate_lowest_one(self) -> Self;
}
impl {i8, i16, i32, i64, i128, isize} {
const fn isolate_highest_one(self) -> Self;
const fn isolate_lowest_one(self) -> Self;
}
impl NonZeroT {
const fn isolate_highest_one(self) -> Self;
const fn isolate_lowest_one(self) -> Self;
}
Steps / History
- Implementation:
- Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
Function name length
RESOLVED - #136909 (comment)
Functions have been renamed to isolate_highest_one
/isolate_lowest_one
The initial function names are taken from the libs-api suggestions in the ACP, but they are quite verbose.
The names need to indicate that the integer being returned is the input with only the most/least significant set bit and not whether the most/least significant bit is 0 or 1. Hence, isolate
is suggested as a prefix to disambiguate the meaning.
assert_eq!(u8::isolate_most_significant_one(0b01100100), 0b01000000);
assert_eq!(u8::isolate_least_significant_one(0b01100100), 0b00000100);
Possible names (non-exhaustive):
isolate_least_significant_one
/isolate_most_significant_one
least_sig_one
/most_sig_one
lowest_one
/highest_one
lowest_bit_set
/highest_bit_set
isolate_lowest_one
/isolate_highest_one
trailing_one
/leading_one