<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="">Sorry, I misspoke. I just meant define it like this:<div class=""><div style="margin: 0px; line-height: normal; font-family: 'Fira Mono'; color: rgb(147, 161, 161);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">public</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">enum</span><span style="font-variant-ligatures: no-common-ligatures" class=""> IntegerSign&lt;T: SignedIntegerType&gt; : </span><span style="font-variant-ligatures: no-common-ligatures; color: #278bd2" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; line-height: normal; font-family: 'Fira Mono';" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#93a1a1" class="">&nbsp; &nbsp;&nbsp;</font></span><span style="color: rgb(211, 54, 130); font-variant-ligatures: no-common-ligatures;" class="">case</span><span style="color: rgb(147, 161, 161); font-variant-ligatures: no-common-ligatures;" class=""> Negative = -</span><span style="color: rgb(108, 113, 196); font-variant-ligatures: no-common-ligatures;" class="">1</span></div><div style="margin: 0px; line-height: normal; font-family: 'Fira Mono';" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#93a1a1" class="">&nbsp; &nbsp;&nbsp;</font></span><span style="color: rgb(211, 54, 130); font-variant-ligatures: no-common-ligatures;" class="">case</span><span style="color: rgb(147, 161, 161); font-variant-ligatures: no-common-ligatures;" class=""> Zero = </span><span style="color: rgb(108, 113, 196); font-variant-ligatures: no-common-ligatures;" class="">0</span></div><div style="margin: 0px; line-height: normal; font-family: 'Fira Mono';" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#93a1a1" class="">&nbsp; &nbsp;&nbsp;</font></span><span style="color: rgb(211, 54, 130); font-variant-ligatures: no-common-ligatures;" class="">case</span><span style="color: rgb(147, 161, 161); font-variant-ligatures: no-common-ligatures;" class=""> Positive = </span><span style="color: rgb(108, 113, 196); font-variant-ligatures: no-common-ligatures;" class="">1</span></div><div style="margin: 0px; line-height: normal; font-family: 'Fira Mono';" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#93a1a1" class="">&nbsp; &nbsp;&nbsp;</font></span><span style="color: rgb(211, 54, 130); font-variant-ligatures: no-common-ligatures;" class="">public</span><span style="color: rgb(147, 161, 161); font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="color: rgb(211, 54, 130); font-variant-ligatures: no-common-ligatures;" class="">var</span><span style="color: rgb(147, 161, 161); font-variant-ligatures: no-common-ligatures;" class=""> signum: </span><span style="color: rgb(41, 161, 152); font-variant-ligatures: no-common-ligatures;" class="">T</span><span style="color: rgb(147, 161, 161); font-variant-ligatures: no-common-ligatures;" class=""> {</span></div><div style="margin: 0px; line-height: normal; font-family: 'Fira Mono';" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#93a1a1" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</font><font color="#d33682" class="">return</font></span><span style="color: rgb(147, 161, 161); font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="color: rgb(41, 161, 152); font-variant-ligatures: no-common-ligatures;" class="">T</span><span style="color: rgb(147, 161, 161); font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="color: rgb(211, 54, 130); font-variant-ligatures: no-common-ligatures;" class="">self</span><span style="color: rgb(147, 161, 161); font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="color: rgb(41, 161, 152); font-variant-ligatures: no-common-ligatures;" class="">rawValue</span><span style="color: rgb(147, 161, 161); font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="color: rgb(39, 139, 210); font-variant-ligatures: no-common-ligatures;" class="">toIntMax</span><span style="color: rgb(147, 161, 161); font-variant-ligatures: no-common-ligatures;" class="">())</span></div><div style="margin: 0px; line-height: normal; font-family: 'Fira Mono'; color: rgb(147, 161, 161);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; line-height: normal; font-family: 'Fira Mono'; color: rgb(147, 161, 161);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Although, come to think of it, I’m not sure if that’s an exact drop-in replacement for your code, since it’s `SignedIntegerType` instead of `SignedNumberType`</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">-Dave Sweeris</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div><blockquote type="cite" class=""><div class="">On May 23, 2016, at 11:48 PM, Charlie Monroe &lt;<a href="mailto:charlie@charliemonroe.net" class="">charlie@charliemonroe.net</a>&gt; 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="">Sure, that's a good idea, though I'd personally use the signum var, since using rawValue seems like a bit of an abuse of the fact the enum is defined this way and doesn't help readability of the code:<div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">enum</span><span style="font-variant-ligatures: no-common-ligatures" class=""> IntegerSign&lt;NumberType: SignedNumberType&gt;: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">RawRepresentable</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; line-height: normal; min-height: 10px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Negative</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Zero</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Positive</span></div><div style="margin: 0px; line-height: normal; min-height: 10px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">init</span><span style="font-variant-ligatures: no-common-ligatures" class="">?(rawValue: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">NumberType</span><span style="font-variant-ligatures: no-common-ligatures" class="">) {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span><span style="font-variant-ligatures: no-common-ligatures" class=""> rawValue </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">==</span><span style="font-variant-ligatures: no-common-ligatures" class=""> -</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = .</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">Negative</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; } </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">else</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span><span style="font-variant-ligatures: no-common-ligatures" class=""> rawValue </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">==</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = .</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">Zero</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; } </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">else</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span><span style="font-variant-ligatures: no-common-ligatures" class=""> rawValue </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">==</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = .</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">Positive</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; } </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">else</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">nil</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; line-height: normal; min-height: 10px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> rawValue: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">NumberType</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">signum</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; line-height: normal; min-height: 10px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> signum: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">NumberType</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">switch</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> .</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">Negative</span><span style="font-variant-ligatures: no-common-ligatures" class="">:</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> -</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">as</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">NumberType</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> .</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">Zero</span><span style="font-variant-ligatures: no-common-ligatures" class="">:</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">as</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">NumberType</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> .</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">Positive</span><span style="font-variant-ligatures: no-common-ligatures" class="">:</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">as</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">NumberType</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; line-height: normal; min-height: 10px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; line-height: normal; min-height: 10px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(112, 61, 170);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">SignedNumberType</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> sign: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">IntegerSign</span><span style="font-variant-ligatures: no-common-ligatures" class="">&lt;</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Self</span><span style="font-variant-ligatures: no-common-ligatures" class="">&gt; {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">==</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> .</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">Zero</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; } </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">else</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">&gt;</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> .</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">Positive</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; } </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">else</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> .</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">Negative</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On May 24, 2016, at 6:09 AM, David Sweeris &lt;<a href="mailto:davesweeris@mac.com" class="">davesweeris@mac.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="content-type" content="text/html; charset=utf-8" class=""><div dir="auto" class=""><div class="">Can we make it RawRepresentable? That way signum can just return self.rawValue<br class=""><br class="">Sent from my iPhone</div><div class=""><br class="">On May 23, 2016, at 06:05, Charlie Monroe via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class="">The clean way would be to make it an enum with var signum that would return -1, 0, 1:<div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">enum</span><span style="font-variant-ligatures: no-common-ligatures" class=""> IntegerSign&lt;NumberType: SignedNumberType&gt; {</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo; min-height: 10px;" class=""><br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Negative</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">&nbsp; &nbsp; case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Zero</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">&nbsp; &nbsp; case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Positive</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo; min-height: 10px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">&nbsp; &nbsp; var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> signum: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">NumberType</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp;&nbsp;</span>&nbsp; &nbsp;&nbsp;<span style="font-variant-ligatures: no-common-ligatures;" class="">switch</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures;" class="">self</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">&nbsp; &nbsp;&nbsp;</span>&nbsp; &nbsp;&nbsp;<span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">case</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> .Negative:</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp;&nbsp;</span>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="font-variant-ligatures: no-common-ligatures;" class="">return</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> -</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">1</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures;" class="">as</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">NumberType</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">&nbsp; &nbsp;&nbsp;</span>&nbsp; &nbsp;&nbsp;<span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">case</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> .Zero:</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp;&nbsp;</span>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="font-variant-ligatures: no-common-ligatures;" class="">return</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">0</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures;" class="">as</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">NumberType</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">&nbsp; &nbsp;&nbsp;</span>&nbsp; &nbsp;&nbsp;<span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">case</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> .Positive:</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp;&nbsp;</span>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="font-variant-ligatures: no-common-ligatures;" class="">return</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">1</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures;" class="">as</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">NumberType</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp;&nbsp;</span>&nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo; min-height: 10px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo; min-height: 10px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">SignedNumberType</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">&nbsp; &nbsp; var</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> sign: </span><span style="font-variant-ligatures: no-common-ligatures" class="">IntegerSign</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&lt;</span><span style="font-variant-ligatures: no-common-ligatures" class="">Self</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&gt; {</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">&nbsp; &nbsp;&nbsp;</span>&nbsp; &nbsp;&nbsp;<span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">if</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">self</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> == </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">0</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">&nbsp; &nbsp;&nbsp;</span>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">return</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> .Zero</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp;&nbsp;</span>&nbsp; &nbsp;&nbsp;<span style="font-variant-ligatures: no-common-ligatures;" class="">} </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">else</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">if</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">self</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> &gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">0</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">&nbsp; &nbsp;&nbsp;</span>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">return</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> .Positive</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp;&nbsp;</span>&nbsp; &nbsp;&nbsp;<span style="font-variant-ligatures: no-common-ligatures;" class="">} </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">else</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">&nbsp; &nbsp;&nbsp;</span>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">return</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> .Negative</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp;&nbsp;</span>&nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class="">Charlie<br class=""><div class=""><div class=""><div class=""><div class=""><div class="">
</div>
<br class=""><div class=""><blockquote type="cite" class=""><div class="">On May 23, 2016, at 9:29 AM, Haravikk 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=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Could you give an example of this method’s usage? Surely your value is either positive, negative or zero already, so this method doesn’t return anything more useful.</div><div class=""><br class=""></div><div class="">In other words, anywhere that I might do this:</div><div class=""><br class=""></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>if myValue.sign &gt; 0 { … }</font></div><div class=""><br class=""></div><div class="">I could just as easily do:</div><div class=""><br class=""></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>if myValue &gt; 0 { … }</font></div><div class=""><br class=""></div><div class="">To the same end result surely? Unless I’m missing something it seems redundant.</div><div class=""><br class=""></div><div class="">If there is a use-case for this, would it make more sense to have the return type as an enum with cases for Positive, Negative and Zero?</div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 22 May 2016, at 08:07, Adam Nemecek 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=""><div dir="ltr" class=""><div class="">Howdy,</div><div class="">I think that the SignedNumberType should implement a method called sign that will return -1 for negative numbers, 0 for 0 and 1 for positive numbers. This is similar to the signum method in e.g. Java and similarly called methods in other languages.</div><div class=""><br class=""></div><div class="">The implementation is fairly straight forward</div><div class=""><br class=""></div><div class="">extension SignedNumberType {</div><div class="">&nbsp; var sign: Self {</div><div class="">&nbsp; &nbsp; if self == 0 {</div><div class="">&nbsp; &nbsp; &nbsp; return 0</div><div class="">&nbsp; &nbsp; }</div><div class="">&nbsp; &nbsp; else if self &gt; 0 {</div><div class="">&nbsp; &nbsp; &nbsp; return 1</div><div class="">&nbsp; &nbsp; }</div><div class="">&nbsp; &nbsp; return -1</div><div class="">&nbsp; }</div><div class="">}&nbsp;</div><div class=""><br class=""></div><div class="">I was trying to implement is without branching by doing (x &gt; 0) - (x &lt; 0) but I couldn't get the types right so I'm open to suggestions.</div><div class=""><br class=""></div><div class=""><br class=""></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=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></div></div></div></div></div></blockquote><blockquote type="cite" class=""><div class=""><span class="">_______________________________________________</span><br class=""><span class="">swift-evolution mailing list</span><br class=""><span class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a></span><br class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class=""></div></blockquote></div></div></blockquote></div><br class=""></div></div></div></div></blockquote></div><br class=""></div></body></html>