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

Tracking issue for integer methods for Wrapping #32463

Open
SimonSapin opened this Issue Mar 24, 2016 · 9 comments

Comments

Projects
None yet
10 participants
@SimonSapin
Copy link
Contributor

SimonSapin commented Mar 24, 2016

u32 and other primitive integer types implement a number of bit-manipulation methods like rotate_left, but Wrapping<_> does not. At the moment this can be worked around with code like Wrapping(x.0.rotate_left(n)) instead of x.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 #49393
  • signum #49393
  • is_positive #49393
  • is_negative #49393

and 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

  • Decide on correct behavior for wrapping_next_power_of_two
@srinivasreddy

This comment has been minimized.

Copy link
Contributor

srinivasreddy commented Mar 24, 2016

I want to take this. Would you review my PR?

@steveklabnik steveklabnik added the A-libs label Mar 24, 2016

@SimonSapin

This comment has been minimized.

Copy link
Contributor

SimonSapin commented Mar 25, 2016

I can have a look, but I’m not one of the reviewers who can approve PRs for merging into this repository.

@srinivasreddy

This comment has been minimized.

Copy link
Contributor

srinivasreddy commented Mar 25, 2016

sure that helps. thanks.

@dtolnay

This comment has been minimized.

Copy link
Member

dtolnay commented Nov 17, 2017

I would be open to considering a PR that adds these methods.

Phlosioneer added a commit to Phlosioneer/rust that referenced this issue Mar 7, 2018

Impl 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

kennytm added a commit to kennytm/rust that referenced this issue Mar 10, 2018

Rollup merge of rust-lang#48810 - Phlosioneer:32463-impl-integer-for-…
…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

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Mar 12, 2018

Rollup merge of rust-lang#48810 - Phlosioneer:32463-impl-integer-for-…
…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

bors added a commit that referenced this issue Mar 14, 2018

Auto merge of #48810 - Phlosioneer:32463-impl-integer-for-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 #32463

Phlosioneer added a commit to Phlosioneer/rust that referenced this issue Mar 19, 2018

Impl 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

kennytm added a commit to kennytm/rust that referenced this issue Mar 19, 2018

Rollup merge of rust-lang#48810 - Phlosioneer:32463-impl-integer-for-…
…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

@bors bors closed this in #48810 Mar 20, 2018

@clarcharr

This comment has been minimized.

Copy link
Contributor

clarcharr commented Mar 26, 2018

This is a tracking issue, so, it shouldn't be closed.

Also, a quick search yields that we are missing:

  • min_value and max_value (mostly useful for macros)
  • from_str_radix (changes behaviour)
  • reverse_bits (added after initial PR)
  • abs (missing; should call wrapping_abs)
  • signum(presumably missed, as this is specific to signed integers)
  • is_positive and is_negative (same as above)

@SimonSapin SimonSapin reopened this Mar 26, 2018

@SimonSapin SimonSapin changed the title Integer methods for Wrapping Tracking issue for integer methods for Wrapping Mar 26, 2018

@fbstj

This comment has been minimized.

Copy link
Contributor

fbstj commented Mar 27, 2018

is it worth changing the top post into a checklist to track completion? since this is a tracking issue.

@scottmcm

This comment has been minimized.

Copy link
Member

scottmcm commented Apr 18, 2018

I guess now mod_euc and div_euc need to go on the list too? #49389

@varkor

This comment has been minimized.

Copy link
Member

varkor commented May 21, 2018

Bit-shifting would be useful to have here too.

bors added a commit that referenced this issue May 28, 2018

Auto merge of #50465 - clarcharr:wrapping, r=KodrAus
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.
@briansmith

This comment has been minimized.

Copy link

briansmith commented Dec 1, 2018

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 Wrapping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment