-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Tracking issue for integer methods for Wrapping #32463
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
I want to take this. Would you review my PR? |
I can have a look, but I’m not one of the reviewers who can approve PRs for merging into this repository. |
sure that helps. thanks. |
I would be open to considering a PR that adds these methods. |
Wrapping<T> now implements: count_ones, count_zeros, leading_zeros, trailing_zeros, rotate_left, rotate_right, swap_bytes, from_be, from_le, to_be, to_le, and pow where T is: u8, u16, u32, u64, usize, i8, i16, i32, i64, or isize. Docs were written for all these methods, as well as examples. The examples mirror the ones on u8, u16, etc... for consistency. Closes rust-lang#32463
…wrapping, r=dtolnay Implement Integer methods for Wrapping Wrapping<T> now implements: count_ones, count_zeros, leading_zeros, trailing_zeros, rotate_left, rotate_right, swap_bytes, from_be, from_le, to_be, to_le, and pow where T is: u8, u16, u32, u64, usize, i8, i16, i32, i64, or isize. Docs were written for all these methods, as well as examples. The examples mirror the ones on u8, u16, etc... for consistency. Closes rust-lang#32463
…wrapping, r=dtolnay Implement Integer methods for Wrapping Wrapping<T> now implements: count_ones, count_zeros, leading_zeros, trailing_zeros, rotate_left, rotate_right, swap_bytes, from_be, from_le, to_be, to_le, and pow where T is: u8, u16, u32, u64, usize, i8, i16, i32, i64, or isize. Docs were written for all these methods, as well as examples. The examples mirror the ones on u8, u16, etc... for consistency. Closes rust-lang#32463
Wrapping<T> now implements: count_ones, count_zeros, leading_zeros, trailing_zeros, rotate_left, rotate_right, swap_bytes, from_be, from_le, to_be, to_le, and pow where T is: u8, u16, u32, u64, usize, i8, i16, i32, i64, or isize. Docs were written for all these methods, as well as examples. The examples mirror the ones on u8, u16, etc... for consistency. Closes rust-lang#32463
…wrapping, r=dtolnay Implement Integer methods for Wrapping Wrapping<T> now implements: count_ones, count_zeros, leading_zeros, trailing_zeros, rotate_left, rotate_right, swap_bytes, from_be, from_le, to_be, to_le, and pow where T is: u8, u16, u32, u64, usize, i8, i16, i32, i64, or isize. Docs were written for all these methods, as well as examples. The examples mirror the ones on u8, u16, etc... for consistency. Closes rust-lang#32463
This is a tracking issue, so, it shouldn't be closed. Also, a quick search yields that we are missing:
|
is it worth changing the top post into a checklist to track completion? since this is a tracking issue. |
I guess now |
Bit-shifting would be useful to have here too. |
Add missing Wrapping methods, use doc_comment! Re-opened version of #49393 . Finishing touches for #32463. Note that this adds `Shl` and `Shr` implementations for `Wrapping<i128>` and `Wrapping<u128>`, which were previously missed. This is technically insta-stable, but I don't know why this would be a problem.
I would like to propose that all of the ones that have been implemented already be stabilized, and that we separate the ones that haven't been implemented into a separate feature. Otherwise stabilization is likely to lose many races with adding new methods to integer types that then should be added to |
Any movement on the semantics of |
I strongly believe that |
Adding the other argument: if you see integers as infinite, rather than finite, zero is never a power of two; therefore, the wrapping version should wrap to one. It's been argued that there is a way to make both versions as performant as one another (and hence the argument is just over preference of the result) but I don't actually know the code for this case. (Maybe @nagisa can comment on that.) |
I consider As for implementation, since the of |
Maybe this is too much, but given that we're implementing the same methods for a bunch of different |
Pre-1.0 Rust had a |
I was specifically thinking of a |
|
There is a further argument for
to obtain the bitmask of all numbers in |
Note that
If people want that, I would encourage them to propose it as a separate method. It's nicer than Strawman for a bikeshed: |
Is there still debate around the behavior of If there is a debate around this, how can I get involved to push for stabilization? |
This keeps `Wrapping` synchronized with the primitives it wraps as for the rust-lang#32463 `wrapping_int_impl` feature.
add BITS associated constant to core::num::Wrapping This keeps `Wrapping` synchronized with the primitives it wraps as for the rust-lang#32463 `wrapping_int_impl` feature.
Seconding @briansmith 's comment from soon 5 years ago, is there anything blocking stabilization of the basic and uncontroversial methods like It doesn't seem to me that requiring the nightly compiler is justified for trivial 1-line methods that have been around for many years now. Given the lack of discussion here, can one directly send a PR to stabilize some methods? |
How can this be driven forward? Right now
I hope so! |
Would it make sense to make this also include the recently-stabilised |
u32
and other primitive integer types implement a number of bit-manipulation methods likerotate_left
, butWrapping<_>
does not. At the moment this can be worked around with code likeWrapping(x.0.rotate_left(n))
instead ofx.rotate_left(n)
.It would be nice to implement:
count_ones
count_zeroes
leading_zeroes
trailing_zeroes
rotate_left
rotate_right
swap_bytes
from_be
(?)from_le
(?)to_be
to_le
pow
(?)Edit: Others added after #32463 (comment)
is_power_of_two
(?)next_power_of_two
(?)min_value
(?)max_value
(?)from_str_radix
(?)reverse_bits
abs
Add missing Wrapping methods, use doc_comment! #49393Add missing Wrapping methods, use doc_comment! #50465signum
Add missing Wrapping methods, use doc_comment! #49393Add missing Wrapping methods, use doc_comment! #50465is_positive
Add missing Wrapping methods, use doc_comment! #49393Add missing Wrapping methods, use doc_comment! #50465is_negative
Add missing Wrapping methods, use doc_comment! #49393Add missing Wrapping methods, use doc_comment! #50465and maybe other methods, for:
Wrapping<u8>
Wrapping<u16>
Wrapping<u32>
Wrapping<u64>
Wrapping<usize>
Wrapping<i8>
Wrapping<i16>
Wrapping<i32>
Wrapping<i64>
Wrapping<isize>
Edit: From #50465
wrapping_next_power_of_two
The text was updated successfully, but these errors were encountered: