-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Implement signum() on unsigned integers #71728
Copy link
Copy link
Open
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
This can be quite useful when writing macros that are generic over any integer.
For example, I just tried writing this code (bar is any of i8, i16, i32, u8, u16, u32 via a macro)
But because
u*::signumisn't implemented, I had to resort to something far more verbose:This can be simplified a bit, but at the expense of performing the operations more than once. This might be optimized away, though.
To allow for the first example to compile (along with the rest of the code, of course), I'd think having
u32::signumreturni32would make sense, despite returning-1being impossible. I definitely think usingsignummakes things clearer and more readable.If this is something that is desired, I can submit a PR.