<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 25 May 2016, at 16:51, Jeremy Pereira &lt;<a href="mailto:jeremy.j.pereira@googlemail.com" class="">jeremy.j.pereira@googlemail.com</a>&gt; wrote:</div><div class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">On 24 May 2016, at 12:33, Haravikk via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><blockquote type="cite" class="">On 23 May 2016, at 20:19, Dany St-Amant via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class="">Challenge accepted… Removed the if/else if, at the cost of double function call to a tri-op:<br class=""><br class="">extension Bool {<br class="">&nbsp;&nbsp;&nbsp;func as01&lt;T:SignedNumberType&gt;() -&gt; T { return self ? 1 : 0 }<br class="">}<br class=""><br class="">extension SignedNumberType {<br class="">&nbsp;&nbsp;&nbsp;var sign: Self { return (self &gt; 0).as01() - (self &lt; 0).as01() }<br class="">}<br class=""></blockquote><br class="">I don’t believe this solves the problem; I think you’ve really just moved the branching into the as01() method.<br class=""><br class="">I think the more correct solution would be for all integer types to have a required Bool initialiser in a protocol somewhere, this way you could just do:<br class=""><br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>var sign:Self { return Self(boolValue: self &gt; 0) - Self(boolValue: self &lt; 0) }<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Aren’t you just hiding the branches in the initialiser there?</span></div></blockquote></div><br class=""><div class="">Shouldn’t have to but possibly yeah; the booleans are just 1-bit values, so they can be extended to fit any integer type, but currently the ability to convert them seems lacking. There’s supposed to be something being done about improving the ability to use numeric types interchangeably (e.g- you should be able to freely fire an Int16 into an Int32 with implicit casting since it definitely fits), but I don’t know if Bool will be included in that or not.</div></body></html>