<div dir="ltr">Also, <font face="monospace, monospace">maximum()</font> should probably return <font face="monospace, monospace">y</font> if x == y to be consistent with <font face="monospace, monospace"><a href="https://github.com/apple/swift/blob/master/stdlib/public/core/Algorithm.swift#L38" target="_blank">max()</a></font>, preserving stable ordering for <font face="monospace, monospace">(x, y) = (min(x, y), max(x, y))</font>. I think IEEE 754 leaves the <font face="monospace, monospace">x == y</font> case unspecified. Currently we have the guarantee below.<div><br><div><pre style="font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;color:rgb(51,51,51)"><span style="color:rgb(150,152,150)">/// (…) Returns `x` if `x &gt;= y`, `y` if `y &gt; x` (…)</span>
<span style="color:rgb(167,29,93)">static</span> <span style="color:rgb(167,29,93)">func</span> <span style="color:rgb(121,93,163)">maximum</span>(x: <span style="color:rgb(167,29,93)">Self</span>, <span style="color:rgb(121,93,163)">_</span> <span>y</span>: <span style="color:rgb(167,29,93)">Self</span>) <span style="color:rgb(167,29,93)">-&gt;</span> Self</pre></div><div class="gmail_extra"><div class="gmail_quote"><br></div><div class="gmail_quote">Patrick</div><div class="gmail_quote"><br></div><div class="gmail_quote">On Sun, May 1, 2016 at 9:03 AM, Patrick Pijnappel <span dir="ltr">&lt;<a href="mailto:patrickpijnappel@gmail.com" target="_blank">patrickpijnappel@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Am I correct in assuming that this would also eliminate the hidden <span style="color:rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap">associatedtype _BitsType</span><span style="color:rgb(51,51,51);font-size:12px;white-space:pre-wrap"><font face="arial, helvetica, sans-serif"> currently preventing non-stdlib conformances?</font></span></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Apr 27, 2016 at 2:04 AM, Xiaodi Wu via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra">I thought you&#39;d mentioned that AbsoluteValuable conformance was removed for a reason and that the method would be added to FloatingPoint? Otherwise, it seems like conformance to AbsoluteValuable would be much the same...</div><div><div><div class="gmail_extra"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 26, 2016 at 6:54 PM, Stephen Canon <span dir="ltr">&lt;<a href="mailto:scanon@apple.com" target="_blank">scanon@apple.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div>Do you actually want a method added, or just conformance to AbsoluteValuable?</div><div><br></div><div>– Steve</div><div><div><br><div><blockquote type="cite"><div>On Apr 26, 2016, at 7:41 PM, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>&gt; wrote:</div><br><div><div dir="ltr">Unrelated to this discussion about comparison operators, please remember to put back .abs() or .absoluteValue() somewhere in FloatingPoint. Thanks!<div><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 26, 2016 at 12:07 PM, Nicola Salmoria via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>If performance is the only reasons to have a separate method, perhaps it might make sense to have a note about this in the isLessThanOrEqualTo description, and provide a default implementation that calls down on isLess and isEqual.<br><br></div>Nicola<br><br></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 26, 2016 at 4:59 PM, Stephen Canon <span dir="ltr">&lt;<a href="mailto:scanon@apple.com" target="_blank">scanon@apple.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><span><blockquote type="cite">On Apr 26, 2016, at 10:03 AM, Nicola Salmoria via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br></blockquote><div><blockquote type="cite"><div><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">it should be enough to do</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">func &lt;= &lt;T: FloatingPoint&gt;(lhs: T, rhs: T) -&gt; Bool</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">{  </span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:pre-wrap;word-spacing:0px">        </span><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">return lhs.isLess(than: rhs) || lhs.isEqual(to: rhs)</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">}</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">Or is there some case of x, y where (x &lt;= y) is true but (x &lt; y) and (x == y) are both false?</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"></div></blockquote></div><br></span><div>No, these are always equivalent.</div><div><br></div><div>However, there is a problem with this approach: the compiler knows about the built-in floating-point types (Float, Double, Float80) and their aliases (CGFloat, etc) and can fuse the two comparisons into a single hardware operation.  However, for soft-float types, without a lessThanOrEqual method, there is no single comparison that the compiler could fuse these to.</div><div><br></div><div>In some cases, if they are simple enough, the compiler may be able to actually fuse the bodies of the two comparison operations, but we can’t reasonably depend on that happening or even being possible in all cases.  So for performance, it’s important that there be an actual less than or equal to method.</div><div><br></div><div>– Steve</div></div></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div></div></div>
</div></blockquote></div><br></div></div></div></blockquote></div><br></div></div></div></div>
<br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>
</div></div></blockquote></div><br></div></div></div>