Uh oh!
There was an error while loading. Please reload this page.
Add functions to add unsigned and signed integers - #87601
Conversation
rust-highfive
commented
Jul 29, 2021
r? @kennytm (rust-highfive has picked a reviewer for you, use r? to override) |
leonardo-m
commented
Jul 29, 2021
What are two (different from each other) use cases? |
joshtriplett
commented
Jul 30, 2021
I've wanted both the checked and the wrapping versions of this many times. |
Uh oh!
There was an error while loading. Please reload this page.
scottmcm
commented
Aug 2, 2021
Possibly-silly question: shouldn't there also be |
a1phyr
commented
Aug 2, 2021
Yes, I think that it would be less useful but certainly more consistent. Also in this case we would need |
bors
commented
Aug 7, 2021
☔ The latest upstream changes (presumably #87408) made this pull request unmergeable. Please resolve the merge conflicts. |
23fb4c9 to
b3f4edfComparea1phyr
commented
Aug 7, 2021
Fixed conflicts, added tracking issue, added signed with unsigned operations and renamed feature. |
bors
commented
Aug 31, 2021
☔ The latest upstream changes (presumably #88535) made this pull request unmergeable. Please resolve the merge conflicts. |
b3f4edf to
2132a9fComparebors
commented
Oct 1, 2021
☔ The latest upstream changes (presumably #89414) made this pull request unmergeable. Please resolve the merge conflicts. |
Co-authored-by: kennytm <kennytm@gmail.com>
2132a9f to
9faf621Comparea1phyr
commented
Oct 1, 2021
Rebased |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: kennytm <kennytm@gmail.com>
This comment has been minimized.
This comment has been minimized.
kennytm
commented
Oct 5, 2021
@bors r+ |
bors
commented
Oct 5, 2021
📌 Commit 47edde1 has been approved by |
…ennytm
Add functions to add unsigned and signed integers
This PR adds methods to unsigned integers to add signed integers with good overflow semantics under `#![feature(mixed_integer_ops)]`.
The added API is:
```rust
// `uX` is `u8`, `u16`, `u32`, `u64`,`u128`, `usize`
impl uX {
pub const fn checked_add_signed(self, iX) -> Option<Self>;
pub const fn overflowing_add_signed(self, iX) -> (Self, bool);
pub const fn saturating_add_signed(self, iX) -> Self;
pub const fn wrapping_add_signed(self, iX) -> Self;
}
impl iX {
pub const fn checked_add_unsigned(self, uX) -> Option<Self>;
pub const fn overflowing_add_unsigned(self, uX) -> (Self, bool);
pub const fn saturating_add_unsigned(self, uX) -> Self;
pub const fn wrapping_add_unsigned(self, uX) -> Self;
pub const fn checked_sub_unsigned(self, uX) -> Option<Self>;
pub const fn overflowing_sub_unsigned(self, uX) -> (Self, bool);
pub const fn saturating_sub_unsigned(self, uX) -> Self;
pub const fn wrapping_sub_unsigned(self, uX) -> Self;
}
```
Maybe it would be interesting to also have `add_signed` that panics in debug and wraps in release ?bors
commented
Oct 6, 2021
⌛ Testing commit 47edde1 with merge 7d03fb603a9cca45cb32a9050881bce9f491746e... |
bors
commented
Oct 6, 2021
💔 Test failed - checks-actions |
rust-log-analyzer
commented
Oct 6, 2021
A job failed! Check out the build log: (web)(plain) Click to see the possible cause of the failure (guessed by this bot) |
a1phyr
commented
Oct 6, 2021
This looks like a spurious network error :/ |
Mark-Simulacrum
commented
Oct 6, 2021
…arth Rollup of 12 pull requests Successful merges: - rust-lang#87601 (Add functions to add unsigned and signed integers) - rust-lang#88523 (Expand documentation for `FpCategory`.) - rust-lang#89050 (refactor: VecDeques Drain fields to private) - rust-lang#89245 (refactor: make VecDeque's IterMut fields module-private, not just crate-private) - rust-lang#89324 (Rename `std::thread::available_conccurrency` to `std::thread::available_parallelism`) - rust-lang#89329 (print-type-sizes: skip field printing for primitives) - rust-lang#89501 (Note specific regions involved in 'borrowed data escapes' error) - rust-lang#89506 (librustdoc: Use correct heading levels.) - rust-lang#89528 (Fix suggestion to borrow when casting from pointer to reference) - rust-lang#89531 (library std, libc dependency update) - rust-lang#89588 (Add a test for generic_const_exprs) - rust-lang#89591 (fix: alloc-optimisation is only for rust llvm) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This PR adds methods to unsigned integers to add signed integers with good overflow semantics under
#![feature(mixed_integer_ops)].The added API is:
Maybe it would be interesting to also have
add_signedthat panics in debug and wraps in release ?