Repository navigation
Conversation
|
Doesn't borrow ideas from #1530 ? |
|
@SoniEx2 This is just the wrapper-types themselves, not how they are implemented (eg. the proposed As for traits to identify if a type is wrapping or not, that could be put in the |
|
|
||
| * `/` and `%` cannot overflow on unsigned integers. For signed integers `MIN / -1` and `MIN % -1` | ||
| can overflow since signed types follow two's complement: `-1 * MIN = MAX + 1` and `MIN` is | ||
| always even. The proposed results are `MIN / -1 = MAX` and `MIN % -1 = MAX`. |
There was a problem hiding this comment.
MIN % -1 is well defined as 0. IIRC the only reason it's not this way in Rust is that it requires an additional branch for every op, but that's required here anyway.
There was a problem hiding this comment.
Good point. Changing to 0 for MIN % -1.
|
👍 on changing the name to avoid confusion with |
|
I want a |
|
I would prefer to get an |
|
🔔 This RFC is now entering its final comment period 🔔 The @rust-lang/libs team is inclined to close this RFC. It's unfortunately been inactive for quite some time now and it seems that the desire here may not be enough to move into the standard library yet. It would likely be worth prototyping this on crates.io and seeing how it plays out there before moving. @rust-lang/libs if you could check off your name below or write a comment below to the contrary: |
|
Ok, the libs team has decided to close, so closing. Thanks regardless though for the RFC @m4rw3r! |
Implement two wrapper-types in
std::numwhich provide two different types of behavior on overflow: saturating arithmetic and always checked arithmetic with the latter signalling a thread panic on overflow.Rendered