Open pnkfelix opened 9 years ago
cc @nikomatsakis
(wait was my logic in the above totally bogus? yikes! namely, (floor(T::MAX + 1) mod 2^N) == 0
, not 1
!)
But in any case, there are other parts in the reasoning above that are really flawed; in particular, it should probably yield T::MIN
, by analogy with how wrapping_mul
behaves, right? (That is, the description "use floor(somethingsomething) mod 2^N" has no basis in what wrapping signed arithmetic does...)
I am working through implementing #560
I had thought, from the name "wrapping", that
int::MIN.wrapped_div(-1)
would be defined as follows:but then I saw this comment on the RFC thread:
https://github.com/rust-lang/rfcs/pull/560#issuecomment-72188471
which suggests: "there is no undefined behaviour or values left (if we agree to defining the result of INT_MIN/-1 as INT_MAX)."
My thinking is that if one wants the latter semantic, then maybe we should give it a name other than
wrapping_div
... e.g. maybe have both:keywords: arithmetic overflow division divide wrapping