-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
uabs/unsigned_abs #2914
Comments
If |
@sollyucko That works playground |
Yes please! |
add `unsigned_abs` to signed integers Mentioned on rust-lang/rfcs#2914 This PR simply adds an `unsigned_abs` to signed integers function which returns the correct absolute value as a unsigned integer.
add `unsigned_abs` to signed integers Mentioned on rust-lang/rfcs#2914 This PR simply adds an `unsigned_abs` to signed integers function which returns the correct absolute value as a unsigned integer.
add `unsigned_abs` to signed integers Mentioned on rust-lang/rfcs#2914 This PR simply adds an `unsigned_abs` to signed integers function which returns the correct absolute value as a unsigned integer.
add `unsigned_abs` to signed integers Mentioned on rust-lang/rfcs#2914 This PR simply adds an `unsigned_abs` to signed integers function which returns the correct absolute value as a unsigned integer.
Looks like this went in: https://doc.rust-lang.org/nightly/std/primitive.i64.html#method.unsigned_abs Anyone interested should follow the tracking issue now: rust-lang/rust#74913 |
It would be great to have a
uabs
orunsigned_abs
(or something else, the name isn't important) method that returns the absolute value of the given signed integer as an unsigned integer of the same size. (e.g.uabs(self: i8) -> u8
)Advantages
Disadvantages
Implementation
Alternatives
x.abs() as uX
iX::MIN.abs()
panics in debug modex.wrapping_abs() as uX
if x == iX::MIN { x as uX } else { x.abs() as uX }
iX::abs
Related: #1017, rust-lang/rust#2353
The text was updated successfully, but these errors were encountered: