<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 23, 2016, at 23:06, Nicola Salmoria via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Fri, Jun 24, 2016 at 12:12 AM, Max Moiseev <span dir="ltr" class=""><<a href="mailto:moiseev@apple.com" target="_blank" class="">moiseev@apple.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Nicola,<br class="">
<br class="">
> For these reasons, I think it would make sense to explicitly request that<br class="">
> the remainder operation never traps, and remove the overflow variants.<br class="">
It will still trap when you divide by 0. But in that case falling back to the same generic overflow logic is not the best idea.<br class="">
I agree that remainder is special, let me see what I can do about it.<br class="">
<br class=""></blockquote><div class=""><br class=""></div><div class="">LOL, yes of course, I forgot about the obvious trapping case.<br class=""><br class=""></div><div class="">However,
division by 0 isn't an overflow: it's an undefined operation. I find it
somewhat surprising that dividedWithOverflow/remainderWithOverflow
allow attempting this operation.<br class=""><br class=""></div><div class="">To me, the intuitive
semantics of the WithOverflow methods are "perform the operation, and if
the result doesn't fit in the given type, return a truncated result and
an overflow flag". This is not what happens when dividing by 0, because
the result simply doesn't exist.<br class=""></div><div class=""><br class=""></div><div class="">I think I would prefer if rhs != 0 was documented as an explicit precondition of the division and remainder operations, and dividedWithOverflow/remainderWithOverflow trapped because of precondition failure.<br class=""><br class=""></div><div class="">If it is desirable that the WithOverflow methods never trap, then I think it would be better to add a `divisionByZero` case to the ArithmeticOverflow enum and return that instead of the generic `overflow`.</div></div></div></div></div></blockquote><br class=""></div><div>IIUC, the WithOverflow flag is only for the INT_MIN / -1 case. (And IIUC, that doesn't affect remainder.)</div><div><br class=""></div><div>Jordan</div><br class=""></body></html>