-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Integer overflow RFC needs more wrapper types #928
Comments
(also, nikomatsakis mentioned to me earlier today that it would be cool if we could teach LLVM to be smart about optimizing |
What is the value of the Self if the overflow value is true? Wrapped overflow? Unspecified? |
@gankro oh; its been useful to me for it to denote wrapped overflow. |
I am now wondering, for Update: see also #964 |
This is an issue in need of a PR to modify RFC #560 (text)
During the course of my work attempting to land the integer overflow checking PRs (see rust-lang/rust#22532), I identified some simple types that we should consider adding to the stdlib.
WrappingOps
Wrapping<N>
, which just marks the type as following the usual arithmetic modulo bitwidth rules. (So this is sort of built-in already, not a new change.)OverflowingOps
, which provides methods for e.g.overflowing_add(self, Self) -> (Self, bool)
, where the returned boolean is a flag indicating whether overflow occurred. This was quite useful for composing certain functions where knowledge of overflow was needed. (i am not sure if aOverflowing<N>
trait is warranted.)SaturatingOps
andSaturating<N>
. (I think we already have the methods for the former; so that is just a question of whether the ops need their its own trait. But I think `Saturating is justified either way.)impl Add<N> for Result<N, Overflow>>
where the result type isResult<N, Overflow>
(andOverflow
is a zero-sized struct). At least, I think this would enable patterns of composition likelet value: N = try!(a + b - c + d);
The text was updated successfully, but these errors were encountered: