-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[libc] first_trailing_one(0) should be 0.
#130155
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -146,8 +146,9 @@ first_trailing_zero(T value) { | |
| template <typename T> | ||
| [[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int> | ||
| first_trailing_one(T value) { | ||
| return value == cpp::numeric_limits<T>::max() ? 0 | ||
| : cpp::countr_zero(value) + 1; | ||
| return (value == 0 || value == cpp::numeric_limits<T>::max()) | ||
|
||
| ? 0 | ||
| : cpp::countr_zero(value) + 1; | ||
| } | ||
|
|
||
| template <typename T> | ||
|
|
||
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.
it should be just
value == 0. Whenvalueis not 0,cpp::countr_zero(value) + 1should be correct.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.
It will fail with inputs like
USHRT_MAXbecause we need it to return 0, butcpp::countr_zero(USHRT_MAX) + 1 = 1.