<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="">FWIW the new integers proposal defines a quotientAndRemainder method for FixedWidthInteger protocol:<div class=""><a href="https://github.com/apple/swift-evolution/pull/598/files#diff-6ef84b28f2eaeb383265ccbb60650022R785" class="">https://github.com/apple/swift-evolution/pull/598/files#diff-6ef84b28f2eaeb383265ccbb60650022R785</a></div><div class=""><br class=""></div><div class="">This is not the default you’re proposing, however...</div><div class=""><br class=""></div><div class="">Max</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 13, 2017, at 4:03 PM, Dan Stenmark via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; 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=""><div style="margin: 0px; line-height: normal;" class="">(I get the feeling the response to this pitch will be overwhelming negative, but <i class="">*deep inhale*</i> here I go!)</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">A common mistake I see programmers make is dividing two integers and expecting a floating-point result.&nbsp; This mostly affect new programmers who haven't learned about ALUs yet, but I sometimes even see veterans make the mistake when they don't realize that neither operand they're passing is floating-point.</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><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; color: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> foo = </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">17</span><span style="font-variant-ligatures: no-common-ligatures" class=""> / </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">5</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures;" class="">( </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">foo</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> )&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" class="">// Huh, why is this 3 and not 3.4?&nbsp; Oh, wait, I'm an idiot.</span></div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">I'd like to propose we make '/' operator on two Ints return a quotient-remainder tuple by default.&nbsp; This should help both new and veteran programmers alike write less error-prone code.</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><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; color: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> (quotient, remainder) = </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">17</span><span style="font-variant-ligatures: no-common-ligatures" class=""> / </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">5</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures" class="">( </span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"Q:</span><span style="font-variant-ligatures: no-common-ligatures" class="">\</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">quotient</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">) R:</span><span style="font-variant-ligatures: no-common-ligatures" class="">\</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">remainder</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">)"</span><span style="font-variant-ligatures: no-common-ligatures" class=""> )&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #008400" class="">// Idiot-proof!</span></div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">Thoughts?</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">Dan</div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>