<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="">Filed as <a href="https://bugs.swift.org/browse/SR-5964" class="">https://bugs.swift.org/browse/SR-5964</a><div class=""><br class=""></div><div class="">Martin<br class=""><div class=""><br class=""></div><div class=""><div><blockquote type="cite" class=""><div class="">On 22. Sep 2017, at 12:11, Alex Blewitt <<a href="mailto:alblue@apple.com" class="">alblue@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hmm... probably worth filing a bug at <a href="https://bugs.swift.org/" class="">https://bugs.swift.org</a> then with the below test case.<div class=""><br class=""></div><div class="">Alex</div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 22 Sep 2017, at 10:14, Martin R <<a href="mailto:martinr448@gmail.com" class="">martinr448@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">But the purpose of <div class=""><br class=""></div><div class=""><pre class="declaration" style="font-size: 11px; font-family: 'SF Mono', Menlo, monospace; margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap;"><span class="syntax-keyword"> func</span> <span class="syntax-identifier">dividedReportingOverflow</span>(<span class="syntax-identifier">by</span> <span class="syntax-param-name">other</span>: <span class="syntax-type"><a href="apple-reference-documentation://hsf4N66ABq" style="color: rgb(0, 136, 204); text-decoration: none;" class="">Int</a></span>) -> (<span class="syntax-identifier">partialValue</span>: <span class="syntax-type"><a href="apple-reference-documentation://hsf4N66ABq" style="color: rgb(0, 136, 204); text-decoration: none;" class="">Int</a></span>, <span class="syntax-identifier">overflow</span>: <span class="syntax-type"><a href="apple-reference-documentation://hsvynwdxKM" style="color: rgb(0, 136, 204); text-decoration: none;" class="">Bool</a></span>)</pre><div class=""><br class=""></div><div class="">is to report an overflow in the return value. And actually this compiles and runs in Xcode 9 if the code is on top-level in main.m:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> <span style="color: #ba2da2" class="">let</span> minusOne = <span style="color: #272ad8" class="">-1</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span><span style="color: #ba2da2" class="">let</span><span style="" class=""> r1 = </span><span style="color: #703daa" class="">Int</span><span style="" class="">.</span><span style="color: #703daa" class="">min</span><span style="" class="">.</span>dividedReportingOverflow<span style="" class="">(by: </span><span style="color: #4f8187" class="">minusOne</span><span style="" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span><span style="color: #3e1e81" class="">print</span><span style="" class="">(</span><span style="color: #4f8187" class="">r1</span><span style="" class="">) </span>// (partialValue: -9223372036854775808, overflow: true)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255); min-height: 13px;" class=""> <br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> <span style="color: #ba2da2" class="">let</span> zero = <span style="color: #272ad8" class="">0</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span><span style="color: #ba2da2" class="">let</span><span style="" class=""> r2 = </span><span style="color: #703daa" class="">Int</span><span style="" class="">.</span><span style="color: #703daa" class="">min</span><span style="" class="">.</span>dividedReportingOverflow<span style="" class="">(by: </span><span style="color: #4f8187" class="">zero</span><span style="" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span><span style="color: #3e1e81" class="">print</span><span style="" class="">(</span><span style="color: #4f8187" class="">r2</span><span style="" class="">) </span>// (partialValue: -9223372036854775808, overflow: true)</div></div><div class=""><br class=""></div><div class="">But the same code inside a function (or do-block) fails to compile:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> <span style="color: #ba2da2" class="">func</span> foo() {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> <span style="color: #ba2da2" class="">let</span> minusOne = <span style="color: #272ad8" class="">-1</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> <span style="color: #ba2da2" class="">let</span> r1 = <span style="color: #703daa" class="">Int</span>.<span style="color: #703daa" class="">min</span>.<span style="color: #3e1e81" class="">dividedReportingOverflow</span>(by: minusOne)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span>// error: division '-9223372036854775808 / -1' results in an overflow</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> <span style="color: #3e1e81" class="">print</span>(r1)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255); min-height: 13px;" class=""> <br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> <span style="color: #ba2da2" class="">let</span> zero = <span style="color: #272ad8" class="">0</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> <span style="color: #ba2da2" class="">let</span> r2 = <span style="color: #703daa" class="">Int</span>.<span style="color: #703daa" class="">min</span>.<span style="color: #3e1e81" class="">dividedReportingOverflow</span>(by: zero)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span>// error: division by zero</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> <span style="color: #3e1e81" class="">print</span>(r2)</div><div style="margin: 0px; font-size: 12px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><span style="font-family: Menlo; font-size: 11px;" class=""> </span><span style="font-family: Menlo; font-size: 11px;" class="">}</span></div></div><div class=""><br class=""></div><div class="">Martin</div><div class=""><br class=""></div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 22. Sep 2017, at 10:19, Alex Blewitt via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Int.min is the smallest negative value, and Int.max is the largest positive value (that fits in an Int). However, the absolute value of Int.min is larger than the absolute value of Int.max. So you can't convert Int.min into -Int.min because it's larger than Int.max.<div class=""><br class=""></div><div class="">In other words, this is expected behaviour :)</div><div class=""><br class=""></div><div class="">For example:</div><div class=""><br class=""></div><div class="">Int.min + Int.max = 1</div><div class=""><br class=""></div><div class="">If they were the same value, it would be zero.</div><div class=""><br class=""></div><div class="">Alex<br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On 22 Sep 2017, at 02:42, Peter W A Wood via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Entering the following statement in a playground gives an overflow error. Where should I report this?<div class=""><br class=""></div><div class="">Statement:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);" class=""><span style="color: #703daa" class="">Int</span><span style="" class="">.</span><span style="color: #703daa" class="">min</span><span style="" class="">.</span><span style="text-decoration: underline" class="">d</span>ividedReportingOverflow<span style="" class="">(by:</span><span style="color: #272ad8" class="">-1</span><span style="" class="">)</span></div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);" class=""><span style="" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class="">Playground log:</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class="">Playground execution failed:</b></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class=""></b></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class="">error: MyPlayground.playground:3:9: error: division '-9223372036854775808 / -1' results in an overflow</b></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class="">Int.min.dividedReportingOverflow(by:-1)</b></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class=""><br class=""></b></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Peter</span></div></div></div>_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" class="">https://lists.swift.org/mailman/listinfo/swift-users</a><br class=""></div></blockquote></div><br class=""></div></div>_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" class="">https://lists.swift.org/mailman/listinfo/swift-users</a><br class=""></div></blockquote></div><br class=""></div></div></div></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></div></div></body></html>