<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></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 Mar 30, 2016, at 12:57 PM, Ted F.A. van Gaalen 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=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Thank you, Robert & Haravikk<div class="">Please allow me to respond in-line hereunder, thanks.<div class="">Ted.<br class=""><div class=""><blockquote type="cite" class=""><div class="">On 30.03.2016, at 16:15, Haravikk <<a href="mailto:swift-evolution@haravikk.me" class="">swift-evolution@haravikk.me</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I’m in favour of implicit conversion for integers where no data can be lost (UInt32 to Int64, Int32 to Int64 etc.), in fact I posted a similar thread a little while ago but can’t find it; there’s something being done with numbers so this may be partly in the works.</div><div class=""><br class=""></div><div class="">I definitely think that implicit conversion for floating point should be avoided, as it can’t be guaranteed </div></div></div></blockquote><div class="">Why? and What cannot be guaranteed? </div></div></div></div></div></div></blockquote></div><div class=""><br class=""></div><div class="">These all fail with a runtime error ("Playground execution aborted: Execution was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)”, if you’re curious):</div><div class=""><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">Int</span><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">Double</span><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures;" class="">.infinity)</span></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal; color: rgb(112, 61, 170);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">Double</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.NaN)</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Double</span>.quietNaN)</span></div></div><div class=""><br class=""></div></div><div class="">And this loop runs for 1024 iterations before finding just one instance where the conversion from Int to Double and back to Int actually gives the right answer:</div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> i = </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">UInt</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">.max) + </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> remainder = </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">UInt</span><span style="font-variant-ligatures: no-common-ligatures" class="">()</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">repeat</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">i</span><span style="font-variant-ligatures: no-common-ligatures" class=""> -= </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> DoubleI = </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">UInt</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Double</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">i</span><span style="font-variant-ligatures: no-common-ligatures" class="">))</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">remainder</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = DoubleI > </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">i</span><span style="font-variant-ligatures: no-common-ligatures" class=""> ? DoubleI - </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">i</span><span style="font-variant-ligatures: no-common-ligatures" class=""> : </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">i</span><span style="font-variant-ligatures: no-common-ligatures" class=""> - DoubleI</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">} </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">while</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">remainder</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> != </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span></div></div><div class=""><br class=""></div><div class="">- Dave Sweeris</div></body></html>