<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=""><div class="">First, this is orthogonal to "adhering to the standard". &nbsp;isTotallyOrdered( ) provides the total order predicate required by IEEE 754. &nbsp;The standard has no opinion about whether or not `&lt;=&gt;` is bound to that predicate.</div><div class=""><br class=""></div><div class="">Personally, I would be OK with using the `isTotallyOrdered` semantics for `&lt;=&gt;`. &nbsp;However, it leads to some behavior that would be surprising for novices: x is NaN, and a set S is { 1, 2, NaN }, but S does not contain x. &nbsp;I am skeptical that the distinction between NaN payloads is salient *for generic code written on Comparable types*. &nbsp;It *is* salient for some (rare!) floating-point specific code, but `isTotallyOrdered` is available for floating-point types.</div><div class=""><br class=""></div><div class="">There’s also the issue that if we want to be able to point at IEEE 754 and say “&lt;=&gt; implements a total order on Level N”, distinguishing distinct NaNs has consequences for other values. &nbsp;In particular, it means that a decimal type should distinguish between 1e0 and 10e-1, because it would necessarily be an ordering on level 3 or 4. &nbsp;For { 1, 20 } to not contain 2e1 seems highly dubious to me.</div><div class=""><br class=""></div><div class="">– Steve</div><br class=""><div><blockquote type="cite" class=""><div class="">On Jul 25, 2016, at 2:23 PM, Nevin Brackett-Rozinsky &lt;<a href="mailto:nevin.brackettrozinsky@gmail.com" class="">nevin.brackettrozinsky@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">Pyry, this proposal looks great to me. My one question is, will I be able to write `someCollection.sort(.ascending)` and get the expected result?&nbsp;(This could be an additive future direction.)</div><div class=""><br class=""></div>Stephen, what is your rationale for wanting `&lt;=&gt;` to identify NaN values with different payloads as `.equal`?<div class=""><br class=""></div><div class="">I believe the IEEE 754 total order specification uses the bit-pattern just as Pyry’s proposal does, and there is value is adhering to the standard. Besides, if someone intentionally wishes to consider all NaN values as equivalent they can use `.isNaN` (or even map them to .nan first for uniformity).</div><div class=""><br class=""></div><div class="">Nevin</div><div class=""><br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Mon, Jul 25, 2016 at 1:26 PM, Stephen Canon via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class="">Hi Pyry —</div><div class=""><br class=""></div><div class="">Dave and I spent some time discussing the details of how this applies to floating point earlier today.&nbsp; We’re now in agreement that &lt;=&gt; should treat -0 and +0 as distinct, and treat all NaNs as .equal.&nbsp; There are three motivating considerations:</div><div class=""><br class=""></div><div class="">1. Although -0 and +0 are “IEEE 754 equal”, there is no computation that can produce both of them.&nbsp; In the parlance of IEEE 754, for any rounding mode, the sets of real values that round to them are disjoint.&nbsp; Because of this, if -0 and +0 appear as members of a set, or as keys in a dictionary, they necessarily are the result of distinct computations or data.</div><div class=""><br class=""></div><div class="">2. Substitutability.&nbsp; Adopting these semantics means that if `x &lt;=&gt; y` is `.equal`, `f(x) &lt;=&gt; f(y)` is also `.equal` for any computation `f(x)` that depends on the represented value (as opposed to the encoding) of its argument.</div><div class=""><br class=""></div><div class="">3. 754 defines four “specification levels”, or models:</div><div class=""><br class=""></div><div class=""><span style="white-space:pre-wrap" class="">        </span>- Level 1: The two-point compactification of the reals, or “extended real numbers”.</div><div class=""><span style="white-space:pre-wrap" class="">        </span>- Level 2: The set of representable floating-point data: {-inf … -0} union { 0 … inf } union { NaN }.</div><div class=""><span style="white-space:pre-wrap" class="">        </span>- Level 3: The set of representations of floating-point data: sign-exponent-significand triples, +/-inf, qNaN, sNaN.</div><div class=""><span style="white-space:pre-wrap" class="">        </span>- Level 4: Floating-point encodings (bit patterns).</div><div class=""><br class=""></div><div class="">The `&lt;=&gt;` semantics we propose constitute a total order on level 2, which is the computable model closest to the (reasonably familiar) extended real numbers.&nbsp; Treating -0 and +0 as .equal would put us in a bit of a no-man’s land between levels 1 and 2.</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">– Steve</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class="">On Jul 25, 2016, at 7:41 AM, Pyry Jahkola &lt;<a href="mailto:pyry.jahkola@iki.fi" target="_blank" class="">pyry.jahkola@iki.fi</a>&gt; wrote:</div><br class=""><div class=""><div style="word-wrap:break-word" class="">Since we're running short on time, and the previous discussion thread diverged, here's my attempt to fix the Comparable protocol.<div class=""><br class=""></div><div class=""><b class="">Pull request:</b>&nbsp;<a href="https://github.com/apple/swift-evolution/pull/464" target="_blank" class="">https://github.com/apple/swift-evolution/pull/464</a></div><div class=""><div class=""><br class=""></div><div class="">TL;DR:</div><div class=""><br class=""></div><div class="">1. Equatable remains unchanged, while Comparable bloats a bit to support several use cases.</div><div class="">2. `a &lt;=&gt; b` is well-defined even if either value is NaN. Zero is equal to minus zero.</div><div class="">3. Types are not strictly required to become totally ordered, even if it's strongly recommended.</div><div class=""><br class=""></div><div class="">— — —</div><div class=""><br class=""></div><div class="">I simply can't see how a pure total order version of Comparable would fit the standard way floating point values are expected to behave. However, I think we can reach a satisfactory conclusion, one that involves no crashing in the standard library, which is what I previously suggested.</div><div class=""><br class=""></div><div class="">What I'm trying to fix is so that all operations listed in&nbsp;<a href="https://dl.dropboxusercontent.com/u/217402/Comparable.pdf" target="_blank" class="">https://dl.dropboxusercontent.com/u/217402/Comparable.pdf</a>&nbsp;abide to laws for types without incomparable values, and that types with weaker order can still work in <i class="">some</i> well-defined way outside their totally ordered range.<br class=""><div class=""><div class=""><br class=""></div><div class="">PS. Forgive me Robert, Jaden, and Harlan for not syncing with you, for time is tight. I can pull back or revise the proposal if you don't want to be involved.</div></div></div><div class=""><br class=""></div><div class="">— Pyry</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><h1 style="margin-right:0px;margin-bottom:16px;margin-left:0px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255);margin-top:0px!important" class="">Formalized Ordering</h1><ul style="padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class=""><li class="">Proposal:&nbsp;<a href="https://github.com/pyrtsa/swift-evolution/blob/ca89e7b3a1dffc99baa695a03544fcba75afd0f3/proposals/NNNN-filename.md" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank" class="">SE-NNNN</a></li><li style="margin-top:0.25em" class="">Authors:&nbsp;<a href="https://github.com/codafi" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank" class="">Robert Widmann</a>,&nbsp;<a href="https://github.com/jadengeller" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank" class="">Jaden Geller</a>,&nbsp;<a href="https://github.com/harlanhaskins" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank" class="">Harlan Haskins</a>,&nbsp;<a href="https://github.com/pyrtsa" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank" class="">Pyry Jahkola</a></li><li style="margin-top:0.25em" class="">Status:&nbsp;<span style="font-weight:600" class="">Awaiting review</span></li><li style="margin-top:0.25em" class="">Review manager: TBD</li></ul><h2 style="margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class=""><a href="https://github.com/pyrtsa/swift-evolution/blob/ca89e7b3a1dffc99baa695a03544fcba75afd0f3/proposals/NNNN-formalized-ordering.md#introduction" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank" class=""><u class=""></u><u class=""></u><u class=""></u><u class=""></u></a>Introduction</h2><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">This proposal cleans up the semantics of ordering relations in the standard library. Our goal is to formalize the total ordering semantics of the&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Comparable</code>&nbsp;protocol and still provide accessible ordering definitions for types without total ordering semantics.</p><h2 style="margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class=""><a href="https://github.com/pyrtsa/swift-evolution/blob/ca89e7b3a1dffc99baa695a03544fcba75afd0f3/proposals/NNNN-formalized-ordering.md#motivation" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank" class=""><u class=""></u><u class=""></u><u class=""></u><u class=""></u></a>Motivation</h2><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">The standard comparison operators have an intuitive meaning to programmers. Swift encourages encoding that in an implementation of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Comparable</code>&nbsp;that respects the rules of a&nbsp;<a href="https://en.wikipedia.org/wiki/Total_order" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank" class="">total order</a>. The standard library takes advantage of these rules to provide consistent implementations for sorting and searching generic collections of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Comparable</code>&nbsp;types.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">Not all types behave so well in this framework, unfortunately. There are cases where the semantics of a total order cannot apply and still maintain the traditional definition of “comparison” over these types. Take, for example, sorting an array of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Float</code>&nbsp;s. Today,&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Float</code>&nbsp;‘s instance of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Comparable</code>&nbsp;follows IEEE-754 and returns&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">false</code>&nbsp;for all comparisons of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">NaN</code>&nbsp;. In order to sort this array,&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">NaN</code>&nbsp;s are considered outside the domain of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">&lt;</code>&nbsp;, and the order of a “sorted” array containing them is undefined.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">In addition, generic algorithms in the Swift Standard Library that make use of the current&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Comparable</code>&nbsp;protocol may have to make twice as many comparisons to request the ordering of values with respect to each other than they should. Having a central operation to return information about the ordering of values once should provide a speedup for these operations.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">In the interest of cleaning up the semantics of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Comparable</code>&nbsp;types of all shapes and sizes and their uses in the Swift Standard Library, this proposal is going to re-arrange the requirements of the&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Comparable</code>&nbsp;and&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Equatable</code>&nbsp;protocols.</p><h2 style="margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class=""><a href="https://github.com/pyrtsa/swift-evolution/blob/ca89e7b3a1dffc99baa695a03544fcba75afd0f3/proposals/NNNN-formalized-ordering.md#proposed-solution" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank" class=""><u class=""></u><u class=""></u><u class=""></u><u class=""></u></a>Proposed solution</h2><h3 style="margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class=""><a href="https://github.com/pyrtsa/swift-evolution/blob/ca89e7b3a1dffc99baa695a03544fcba75afd0f3/proposals/NNNN-formalized-ordering.md#equatable" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank" class=""><u class=""></u><u class=""></u><u class=""></u><u class=""></u></a>Equatable</h3><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">The interface of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Equatable</code>&nbsp;remains unchanged under this proposal. Equatable types should still respect the equivalence laws of&nbsp;<em class="">reflexivity</em>&nbsp;(<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">a == a</code>),&nbsp;<em class="">symmetry</em>&nbsp;(<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">a == b</code>&nbsp;iff&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">b == a</code>), and&nbsp;<em class="">transitivity</em>&nbsp;(if&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">a == b</code>&nbsp;and&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">b == c</code>, then&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">a == c</code>). Further,&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">!=</code>&nbsp;remains a top-level binary operator for which&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">a != b</code>&nbsp;iff&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">!(a == b)</code>.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">Types containing properties&nbsp;<em class="">inessential to equality</em>, however, are allowed to retain their notion of identity. For example&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Array</code>'s&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">capacity</code>&nbsp;isn't considered for equality; and&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">-0.0 == 0.0</code>&nbsp;and&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">"ä" == "a\u{308}"</code>, while&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">(-0.0).sign != (0.0).sign</code>&nbsp;and&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">"ä".utf8.count != "a\u{308}".utf8.count</code>.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">IEEE-754 floating point numbers are allowed to break the reflexivity law by defining that&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">.nan != x</code>&nbsp;for any value of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">x</code>, which is the standard behaviour documented in IEEE-754 and implemented the same way in other programming languages.</p><h3 style="margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class=""><a href="https://github.com/pyrtsa/swift-evolution/blob/ca89e7b3a1dffc99baa695a03544fcba75afd0f3/proposals/NNNN-formalized-ordering.md#comparable" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank" class=""><u class=""></u><u class=""></u><u class=""></u><u class=""></u></a>Comparable</h3><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">The&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Comparable</code>&nbsp;protocol will now require (without default implementation provided) a single operator definition:&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">&lt;=&gt;</code>&nbsp;— the comparison operator. From this, all other comparison operators will be derived so as to respect the total order semantics of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Comparable</code>:</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">To maintain compatibility with IEEE-754, the interface of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Comparable</code>&nbsp;also contains as customization points the operators&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">&lt;</code>,&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">&lt;=</code>, and&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">==</code>&nbsp;(derived from&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Equatable</code>) as well as the static binary functions&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">_min(_:_:)</code>&nbsp;and&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">_max(_:_:)</code>. User-defined types are recommended against overriding the default implementations.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">The uncustomizable top-level binary comparison operators&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">a &gt; b</code>&nbsp;and&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">a &gt;= b</code>&nbsp;are implemented as synonyms to&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">b &lt; a</code>and&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">b &lt;= a</code>, respectively.</p><h3 style="margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class=""><a href="https://github.com/pyrtsa/swift-evolution/blob/ca89e7b3a1dffc99baa695a03544fcba75afd0f3/proposals/NNNN-formalized-ordering.md#standard-library" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank" class=""><u class=""></u><u class=""></u><u class=""></u><u class=""></u></a>Standard Library</h3><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">Unlike a previous revision of this proposal, standard library algorithms specific to&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">FloatingPoint</code>&nbsp;remain unchanged.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">Overloads of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">&lt;=&gt;</code>&nbsp;for tuples of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Comparable</code>&nbsp;elements are provided up to a library-defined arity.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">The intent of this proposal is to later augment the standard library so that functions that take an ordering predicate&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">by: (T, T) -&gt; Bool</code>&nbsp;will have an overload&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">ordering: (T, T) -&gt; Ordering</code>&nbsp;that will provide a — potentially — more efficient implementation. A list of such functions is provided in Future directions.</p><h2 style="margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class=""><a href="https://github.com/pyrtsa/swift-evolution/blob/ca89e7b3a1dffc99baa695a03544fcba75afd0f3/proposals/NNNN-formalized-ordering.md#detailed-design" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank" class=""><u class=""></u><u class=""></u><u class=""></u><u class=""></u></a>Detailed design</h2><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">The&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Comparable</code>&nbsp;protocol will be amended by taking away&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">&gt;</code>&nbsp;and&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">&gt;=</code>, adding customisation points&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">_min(_:_:)</code>, and&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">_max(_:_:)</code>, and introducing the ordering operator&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">&lt;=&gt;</code>&nbsp;that makes use of the&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Ordering</code>&nbsp;enum defined below.</p><div style="margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class=""><pre style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;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-break:normal" class=""><span style="color:rgb(167,29,93)" class="">enum</span> Ordering <span style="color:rgb(167,29,93)" class="">:</span> <span style="color:rgb(0,134,179)" class="">Equatable</span> {
  <span style="color:rgb(167,29,93)" class="">case</span> ascending
  <span style="color:rgb(167,29,93)" class="">case</span> equal
  <span style="color:rgb(167,29,93)" class="">case</span> descending
}

<span style="color:rgb(167,29,93)" class="">infix</span> <span style="color:rgb(167,29,93)" class="">operator</span> <span style="color:rgb(167,29,93)" class="">&lt;=&gt;</span> { <span style="color:rgb(167,29,93)" class="">associativity</span> <span style="color:rgb(167,29,93)" class="">none</span> <span style="color:rgb(167,29,93)" class="">precedence</span> <span style="color:rgb(0,134,179)" class="">130</span> }

<span style="color:rgb(167,29,93)" class="">public</span> <span style="color:rgb(167,29,93)" class="">protocol</span> <span style="color:rgb(0,134,179)" class="">Comparable</span> <span style="color:rgb(167,29,93)" class="">:</span> <span style="color:rgb(0,134,179)" class="">Equatable</span> {
  <span style="color:rgb(150,152,150)" class="">// Implementation required:</span>
  <span style="color:rgb(167,29,93)" class="">static</span> <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">&lt;=&gt;</span>(lhs: <span style="color:rgb(167,29,93)" class="">Self</span>, rhs: <span style="color:rgb(167,29,93)" class="">Self</span>) <span style="color:rgb(167,29,93)" class="">-&gt;</span> Ordering

  <span style="color:rgb(150,152,150)" class="">// Default implementations provided:</span>
  <span style="color:rgb(167,29,93)" class="">static</span> <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">==</span> (lhs: <span style="color:rgb(167,29,93)" class="">Self</span>, rhs: <span style="color:rgb(167,29,93)" class="">Self</span>) <span style="color:rgb(167,29,93)" class="">-&gt;</span> <span style="color:rgb(0,134,179)" class="">Bool</span> // derived from <span style="color:rgb(0,134,179)" class="">Equatable</span>
  <span style="color:rgb(167,29,93)" class="">static</span> <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">&lt;</span>  (lhs: <span style="color:rgb(167,29,93)" class="">Self</span>, rhs: <span style="color:rgb(167,29,93)" class="">Self</span>) <span style="color:rgb(167,29,93)" class="">-&gt;</span> <span style="color:rgb(0,134,179)" class="">Bool</span>
  <span style="color:rgb(167,29,93)" class="">static</span> <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">&lt;=</span> (lhs: <span style="color:rgb(167,29,93)" class="">Self</span>, rhs: <span style="color:rgb(167,29,93)" class="">Self</span>) <span style="color:rgb(167,29,93)" class="">-&gt;</span> <span style="color:rgb(0,134,179)" class="">Bool</span>
  <span style="color:rgb(167,29,93)" class="">static</span> <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">_min</span>(<span style="color:rgb(121,93,163)" class="">_</span> <span class="">lhs</span>: <span style="color:rgb(167,29,93)" class="">Self</span>, <span style="color:rgb(121,93,163)" class="">_</span> <span class="">rhs</span>: <span style="color:rgb(167,29,93)" class="">Self</span>) <span style="color:rgb(167,29,93)" class="">-&gt;</span> Self
  <span style="color:rgb(167,29,93)" class="">static</span> <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">_max</span>(<span style="color:rgb(121,93,163)" class="">_</span> <span class="">lhs</span>: <span style="color:rgb(167,29,93)" class="">Self</span>, <span style="color:rgb(121,93,163)" class="">_</span> <span class="">rhs</span>: <span style="color:rgb(167,29,93)" class="">Self</span>) <span style="color:rgb(167,29,93)" class="">-&gt;</span> Self
}</pre></div><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">The&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">&lt;=&gt;</code>&nbsp;operator defines a relationship between&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">==</code>&nbsp;and&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">&lt;=&gt;</code>&nbsp;such that&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">a == b</code>&nbsp;iff&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">(a &lt;=&gt; b) == .equal</code>, unless&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Self</code>&nbsp;chooses to break the semantics in the way of IEEE-754. Likewise, it should hold that&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">(a &lt;=&gt; b) == .ascending</code>&nbsp;iff&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">a &lt; b</code>, and&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">(a &lt;=&gt; b) != .descending</code>&nbsp;iff&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">a &lt;= b</code>.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">The&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">_min(_:_:)</code>&nbsp;and&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">_max(_:_:)</code>&nbsp;functions should return the lesser or greater of the two operands, respectively, while in case of equal arguments,&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">_min(_:_:)</code>&nbsp;should favour the left-hand side and&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">_max(_:_:)</code>&nbsp;the right-hand side to retain identity, as presently explained in&nbsp;<a href="https://github.com/apple/swift/blob/4614adc16168d612b6fc7e7a161dd5b6b34be704/stdlib/public/core/Algorithm.swift#L17-L20" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank" class="">this comment</a>. Making them customization points of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Comparable</code>, we get to fix their behaviour in the presense of unorderable values (<a href="https://bugs.swift.org/browse/SR-1011" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank" class="">SR-1011</a>).</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">Most user types should only implement&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">&lt;=&gt;</code>&nbsp;and leave the other members of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Equatable</code>&nbsp;and&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Comparable</code>&nbsp;to their default implementations. Note that even&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">==</code>&nbsp;has a sane default implementation if&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Self</code>&nbsp;is made&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Comparable</code>:</p><div style="margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class=""><pre style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;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-break:normal" class=""><span style="color:rgb(150,152,150)" class="">// Default implementations, which should be used for most Comparable types:</span>
<span style="color:rgb(167,29,93)" class="">extension</span> <span style="color:rgb(0,134,179)" class="">Comparable</span> {
  <span style="color:rgb(167,29,93)" class="">static</span> <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">==</span> (l: <span style="color:rgb(167,29,93)" class="">Self</span>, r: <span style="color:rgb(167,29,93)" class="">Self</span>) <span style="color:rgb(167,29,93)" class="">-&gt;</span> <span style="color:rgb(0,134,179)" class="">Bool</span> { <span style="color:rgb(167,29,93)" class="">return</span> (l <span style="color:rgb(167,29,93)" class="">&lt;=&gt;</span> r) <span style="color:rgb(167,29,93)" class="">==</span> <span style="color:rgb(167,29,93)" class="">.</span>equal }
  <span style="color:rgb(167,29,93)" class="">static</span> <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">&lt;</span>  (l: <span style="color:rgb(167,29,93)" class="">Self</span>, r: <span style="color:rgb(167,29,93)" class="">Self</span>) <span style="color:rgb(167,29,93)" class="">-&gt;</span> <span style="color:rgb(0,134,179)" class="">Bool</span> { <span style="color:rgb(167,29,93)" class="">return</span> (l <span style="color:rgb(167,29,93)" class="">&lt;=&gt;</span> r) <span style="color:rgb(167,29,93)" class="">==</span> <span style="color:rgb(167,29,93)" class="">.</span>ascending }
  <span style="color:rgb(167,29,93)" class="">static</span> <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">&lt;=</span> (l: <span style="color:rgb(167,29,93)" class="">Self</span>, r: <span style="color:rgb(167,29,93)" class="">Self</span>) <span style="color:rgb(167,29,93)" class="">-&gt;</span> <span style="color:rgb(0,134,179)" class="">Bool</span> { <span style="color:rgb(167,29,93)" class="">return</span> (l <span style="color:rgb(167,29,93)" class="">&lt;=&gt;</span> r) <span style="color:rgb(167,29,93)" class="">!=</span> <span style="color:rgb(167,29,93)" class="">.</span>descending }
  <span style="color:rgb(167,29,93)" class="">static</span> <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">_min</span>(<span style="color:rgb(121,93,163)" class="">_</span> <span class="">l</span>: <span style="color:rgb(167,29,93)" class="">Self</span>, <span style="color:rgb(121,93,163)" class="">_</span> <span class="">r</span>: <span style="color:rgb(167,29,93)" class="">Self</span>) <span style="color:rgb(167,29,93)" class="">-&gt;</span> Self { <span style="color:rgb(167,29,93)" class="">return</span> r <span style="color:rgb(167,29,93)" class="">&lt;</span> l <span style="color:rgb(167,29,93)" class="">?</span> r <span style="color:rgb(167,29,93)" class="">:</span> l }
  <span style="color:rgb(167,29,93)" class="">static</span> <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">_max</span>(<span style="color:rgb(121,93,163)" class="">_</span> <span class="">l</span>: <span style="color:rgb(167,29,93)" class="">Self</span>, <span style="color:rgb(121,93,163)" class="">_</span> <span class="">r</span>: <span style="color:rgb(167,29,93)" class="">Self</span>) <span style="color:rgb(167,29,93)" class="">-&gt;</span> Self { <span style="color:rgb(167,29,93)" class="">return</span> r <span style="color:rgb(167,29,93)" class="">&lt;</span> l <span style="color:rgb(167,29,93)" class="">?</span> l <span style="color:rgb(167,29,93)" class="">:</span> r }
}

<span style="color:rgb(150,152,150)" class="">// Unoverridable top-level operators and functions for Comparable:</span>
<span style="color:rgb(167,29,93)" class="">public</span> <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">&gt;</span>  &lt;T <span style="color:rgb(167,29,93)" class="">:</span> <span style="color:rgb(0,134,179)" class="">Comparable</span>&gt;(l: T, r: T) <span style="color:rgb(167,29,93)" class="">-&gt;</span> <span style="color:rgb(0,134,179)" class="">Bool</span> { <span style="color:rgb(167,29,93)" class="">return</span> r <span style="color:rgb(167,29,93)" class="">&lt;</span> l }
<span style="color:rgb(167,29,93)" class="">public</span> <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">&gt;=</span> &lt;T <span style="color:rgb(167,29,93)" class="">:</span> <span style="color:rgb(0,134,179)" class="">Comparable</span>&gt;(l: T, r: T) <span style="color:rgb(167,29,93)" class="">-&gt;</span> <span style="color:rgb(0,134,179)" class="">Bool</span> { <span style="color:rgb(167,29,93)" class="">return</span> r <span style="color:rgb(167,29,93)" class="">&lt;=</span> l }
<span style="color:rgb(167,29,93)" class="">public</span> <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">min</span>&lt;T <span style="color:rgb(167,29,93)" class="">:</span> <span style="color:rgb(0,134,179)" class="">Comparable</span>&gt;(<span style="color:rgb(121,93,163)" class="">_</span> <span class="">l</span>: T, <span style="color:rgb(121,93,163)" class="">_</span> <span class="">r</span>: T) <span style="color:rgb(167,29,93)" class="">-&gt;</span> T { <span style="color:rgb(167,29,93)" class="">return</span> T<span style="color:rgb(167,29,93)" class="">.</span>_min(l, r) }
<span style="color:rgb(167,29,93)" class="">public</span> <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">max</span>&lt;T <span style="color:rgb(167,29,93)" class="">:</span> <span style="color:rgb(0,134,179)" class="">Comparable</span>&gt;(<span style="color:rgb(121,93,163)" class="">_</span> <span class="">l</span>: T, <span style="color:rgb(121,93,163)" class="">_</span> <span class="">r</span>: T) <span style="color:rgb(167,29,93)" class="">-&gt;</span> T { <span style="color:rgb(167,29,93)" class="">return</span> T<span style="color:rgb(167,29,93)" class="">.</span>_max(l, r) }</pre></div><h3 style="margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class=""><a href="https://github.com/pyrtsa/swift-evolution/blob/ca89e7b3a1dffc99baa695a03544fcba75afd0f3/proposals/NNNN-formalized-ordering.md#handling-of-floating-point-comparisons" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank" class=""><u class=""></u><u class=""></u><u class=""></u><u class=""></u></a>Handling of floating point comparisons</h3><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class=""><em class="">The following text is written in terms of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Double</code>&nbsp;but other floating-point types (<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Float</code>,&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Float80</code>) are proposed the same treatment.</em></p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">The IEEE-754 floating point specification has two oddities when it comes to orderability: there are two zeros (<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">0.0</code>&nbsp;and&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">-0.0</code>) which are considered equal to each other, and there are&nbsp;<em class="">multiple</em>&nbsp;not-a-number values&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">x</code>&nbsp;for which&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">x.isNaN == true</code>&nbsp;and&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">x != y</code>&nbsp;with any value of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">y</code>, even&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">x</code>&nbsp;itself. (Remark: the most common NaN value is obtained by the static property&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Double.nan</code>.)</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">The interface of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Comparable</code>&nbsp;is designed so that&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">&lt;=&gt;</code>&nbsp;alone is able to produce a total order among all possible&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Double</code>values, sorting negative NaNs less than any other values, and positive NaNs greater than any other. Otherwise, within the range of totally ordered floating point values,&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">-Double.infinity ... Double.infinity</code>, the result of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">a &lt;=&gt; b</code>&nbsp;remains in full agreement with the laws of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">a &lt; b</code>,&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">a &lt;= b</code>, and&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">a == b</code>.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">The suggested implementation of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Double : Comparable</code>&nbsp;makes&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">&lt;=&gt;</code>&nbsp;distinguish between every different&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">bitPattern</code>of NaN:</p><div style="margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class=""><pre style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;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-break:normal" class=""><span style="color:rgb(167,29,93)" class="">extension</span> <span style="color:rgb(0,134,179)" class="">Double</span> <span style="color:rgb(167,29,93)" class="">:</span> <span style="color:rgb(0,134,179)" class="">Comparable</span> {
  <span style="color:rgb(167,29,93)" class="">public</span> <span style="color:rgb(167,29,93)" class="">static</span> <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">&lt;=&gt;</span> (l: <span style="color:rgb(0,134,179)" class="">Double</span>, r: <span style="color:rgb(0,134,179)" class="">Double</span>) <span style="color:rgb(167,29,93)" class="">-&gt;</span> Ordering {
    <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">ordinal</span>(<span style="color:rgb(121,93,163)" class="">_</span> <span class="">x</span>: <span style="color:rgb(0,134,179)" class="">UInt64</span>) <span style="color:rgb(167,29,93)" class="">-&gt;</span> <span style="color:rgb(0,134,179)" class="">UInt64</span> {
      <span style="color:rgb(167,29,93)" class="">return</span> x <span style="color:rgb(167,29,93)" class="">&lt;</span> 0x80000000_00000000 <span style="color:rgb(167,29,93)" class="">?</span> x <span style="color:rgb(167,29,93)" class="">+</span> 0x7fffffff_ffffffff <span style="color:rgb(167,29,93)" class="">:</span> <span style="color:rgb(167,29,93)" class="">~</span>x
    }
    <span style="color:rgb(167,29,93)" class="">return</span> ordinal(l<span style="color:rgb(167,29,93)" class="">.</span>bitPattern) <span style="color:rgb(167,29,93)" class="">&lt;=&gt;</span> ordinal(r<span style="color:rgb(167,29,93)" class="">.</span>bitPattern)
  }
  <span style="color:rgb(167,29,93)" class="">public</span> <span style="color:rgb(167,29,93)" class="">static</span> <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">==</span> (l: <span style="color:rgb(0,134,179)" class="">Double</span>, r: <span style="color:rgb(0,134,179)" class="">Double</span>) <span style="color:rgb(167,29,93)" class="">-&gt;</span> <span style="color:rgb(0,134,179)" class="">Bool</span> { <span style="color:rgb(167,29,93)" class="">return</span> Builtin<span style="color:rgb(167,29,93)" class="">.</span>eq(l, r) }
  <span style="color:rgb(167,29,93)" class="">public</span> <span style="color:rgb(167,29,93)" class="">static</span> <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">&lt;</span>  (l: <span style="color:rgb(0,134,179)" class="">Double</span>, r: <span style="color:rgb(0,134,179)" class="">Double</span>) <span style="color:rgb(167,29,93)" class="">-&gt;</span> <span style="color:rgb(0,134,179)" class="">Bool</span> { <span style="color:rgb(167,29,93)" class="">return</span> Builtin<span style="color:rgb(167,29,93)" class="">.</span>lt(l, r) }
  <span style="color:rgb(167,29,93)" class="">public</span> <span style="color:rgb(167,29,93)" class="">static</span> <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">&lt;=</span> (l: <span style="color:rgb(0,134,179)" class="">Double</span>, r: <span style="color:rgb(0,134,179)" class="">Double</span>) <span style="color:rgb(167,29,93)" class="">-&gt;</span> <span style="color:rgb(0,134,179)" class="">Bool</span> { <span style="color:rgb(167,29,93)" class="">return</span> Builtin<span style="color:rgb(167,29,93)" class="">.</span>le(l, r) }
  <span style="color:rgb(167,29,93)" class="">public</span> <span style="color:rgb(167,29,93)" class="">static</span> <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">_min</span>(l: <span style="color:rgb(0,134,179)" class="">Double</span>, r: <span style="color:rgb(0,134,179)" class="">Double</span>) <span style="color:rgb(167,29,93)" class="">-&gt;</span> <span style="color:rgb(0,134,179)" class="">Double</span> { <span style="color:rgb(167,29,93)" class="">return</span> Builtin<span style="color:rgb(167,29,93)" class="">.</span>fmin(l, r) }
  <span style="color:rgb(167,29,93)" class="">public</span> <span style="color:rgb(167,29,93)" class="">static</span> <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">_max</span>(l: <span style="color:rgb(0,134,179)" class="">Double</span>, r: <span style="color:rgb(0,134,179)" class="">Double</span>) <span style="color:rgb(167,29,93)" class="">-&gt;</span> <span style="color:rgb(0,134,179)" class="">Double</span> { <span style="color:rgb(167,29,93)" class="">return</span> Builtin<span style="color:rgb(167,29,93)" class="">.</span>fmax(l, r) }
}

<span style="color:rgb(150,152,150)" class="">// Likewise:</span>
<span style="color:rgb(167,29,93)" class="">extension</span> <span style="color:rgb(0,134,179)" class="">Float</span> <span style="color:rgb(167,29,93)" class="">:</span> <span style="color:rgb(0,134,179)" class="">Comparable</span> { <span style="color:rgb(167,29,93)" class="">...</span> }
<span style="color:rgb(167,29,93)" class="">extension</span> <span style="color:rgb(0,134,179)" class="">Float80</span> <span style="color:rgb(167,29,93)" class="">:</span> <span style="color:rgb(0,134,179)" class="">Comparable</span> { <span style="color:rgb(167,29,93)" class="">...</span> }</pre></div><h3 style="margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class=""><a href="https://github.com/pyrtsa/swift-evolution/blob/ca89e7b3a1dffc99baa695a03544fcba75afd0f3/proposals/NNNN-formalized-ordering.md#tuples-and-order-reversal" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank" class=""><u class=""></u><u class=""></u><u class=""></u><u class=""></u></a>Tuples and order reversal</h3><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">Due to missing language support, tuples of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Comparable</code>&nbsp;elements cannot be&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Comparable</code>&nbsp;themselves, but in the spirit of&nbsp;<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0015-tuple-comparison-operators.md" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank" class="">SE-0015</a>, such tuples are given their overloads of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">&lt;=&gt;</code>&nbsp;up to a standard library defined maximum arity:</p><div style="margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class=""><pre style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;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-break:normal" class=""><span style="color:rgb(167,29,93)" class="">public</span> <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">&lt;=&gt;</span> &lt;A <span style="color:rgb(167,29,93)" class="">:</span> <span style="color:rgb(0,134,179)" class="">Comparable</span>, B <span style="color:rgb(167,29,93)" class="">:</span> <span style="color:rgb(0,134,179)" class="">Comparable</span>&gt;(lhs: (A, B), rhs: (A, B)) <span style="color:rgb(167,29,93)" class="">-&gt;</span> Ordering {
  <span style="color:rgb(167,29,93)" class="">let</span> a <span style="color:rgb(167,29,93)" class="">=</span> lhs<span style="color:rgb(167,29,93)" class="">.</span><span style="color:rgb(0,134,179)" class="">0</span> <span style="color:rgb(167,29,93)" class="">&lt;=&gt;</span> rhs<span style="color:rgb(167,29,93)" class="">.</span><span style="color:rgb(0,134,179)" class="">0</span>
  <span style="color:rgb(167,29,93)" class="">if</span> a <span style="color:rgb(167,29,93)" class="">!=</span> <span style="color:rgb(167,29,93)" class="">.</span>equal { <span style="color:rgb(167,29,93)" class="">return</span> a }
  <span style="color:rgb(167,29,93)" class="">let</span> b <span style="color:rgb(167,29,93)" class="">=</span> lhs<span style="color:rgb(167,29,93)" class="">.</span><span style="color:rgb(0,134,179)" class="">1</span> <span style="color:rgb(167,29,93)" class="">&lt;=&gt;</span> rhs<span style="color:rgb(167,29,93)" class="">.</span><span style="color:rgb(0,134,179)" class="">1</span>
  <span style="color:rgb(167,29,93)" class="">if</span> b <span style="color:rgb(167,29,93)" class="">!=</span> <span style="color:rgb(167,29,93)" class="">.</span>equal { <span style="color:rgb(167,29,93)" class="">return</span> b }
  <span style="color:rgb(167,29,93)" class="">return</span> <span style="color:rgb(167,29,93)" class="">.</span>equal
}

<span style="color:rgb(150,152,150)" class="">// Similarly for &lt;A : Comparable, B : Comparable, C : Comparable&gt;, etc.</span></pre></div><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">To simplify the reversal of a given ordering operation, two members of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Ordering</code>&nbsp;are provided in an extension:</p><div style="margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class=""><pre style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;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-break:normal" class=""><span style="color:rgb(167,29,93)" class="">extension</span> Ordering {
  <span style="color:rgb(167,29,93)" class="">public</span> <span style="color:rgb(167,29,93)" class="">static</span> <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">reversing</span>&lt;T <span style="color:rgb(167,29,93)" class="">:</span> <span style="color:rgb(0,134,179)" class="">Comparable</span>&gt;(<span style="color:rgb(121,93,163)" class="">_</span> <span class="">ordering</span>: (T, T) <span style="color:rgb(167,29,93)" class="">-&gt;</span> Ordering)
    <span style="color:rgb(167,29,93)" class="">-&gt;</span> (T, T) <span style="color:rgb(167,29,93)" class="">-&gt;</span> Ordering
  {
    <span style="color:rgb(167,29,93)" class="">return</span> { l, r <span style="color:rgb(167,29,93)" class="">in</span> ordering(r, l) }
  }

  <span style="color:rgb(167,29,93)" class="">public</span> <span style="color:rgb(167,29,93)" class="">var</span> reversed: Ordering {
    <span style="color:rgb(167,29,93)" class="">switch</span> <span style="color:rgb(167,29,93)" class="">self</span> {
    <span style="color:rgb(167,29,93)" class="">case</span> <span style="color:rgb(167,29,93)" class="">.</span>ascending:  <span style="color:rgb(167,29,93)" class="">return</span> <span style="color:rgb(167,29,93)" class="">.</span>descending
    <span style="color:rgb(167,29,93)" class="">case</span> <span style="color:rgb(167,29,93)" class="">.</span>equal:      <span style="color:rgb(167,29,93)" class="">return</span> <span style="color:rgb(167,29,93)" class="">.</span>equal
    <span style="color:rgb(167,29,93)" class="">case</span> <span style="color:rgb(167,29,93)" class="">.</span>descending: <span style="color:rgb(167,29,93)" class="">return</span> <span style="color:rgb(167,29,93)" class="">.</span>ascending
    }
  }
}</pre></div><h3 style="margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class=""><a href="https://github.com/pyrtsa/swift-evolution/blob/ca89e7b3a1dffc99baa695a03544fcba75afd0f3/proposals/NNNN-formalized-ordering.md#foundation" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank" class=""><u class=""></u><u class=""></u><u class=""></u><u class=""></u></a>Foundation</h3><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">In addition,&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Foundation</code>&nbsp;code will now bridge&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">NSComparisonResult</code>&nbsp;to&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Ordering</code>&nbsp;allowing for a fluid, natural, and safe API.</p><h2 style="margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class=""><a href="https://github.com/pyrtsa/swift-evolution/blob/ca89e7b3a1dffc99baa695a03544fcba75afd0f3/proposals/NNNN-formalized-ordering.md#impact-on-existing-code" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank" class=""><u class=""></u><u class=""></u><u class=""></u><u class=""></u></a>Impact on existing code</h2><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">The biggest drawback of the proposed design is the large surface area of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Comparable</code>'s interface, as well as the possibility of overriding the comparison operators by mistake. On the other hand, since the required&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">&lt;=&gt;</code>&nbsp;operator is new and affects all users porting their previously&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Comparable</code>&nbsp;data types to Swift 3, we can use documentation to suggest removing the redundant (and possibly faulty) implementations of other comparison operators.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">Existing&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Equatable</code>&nbsp;but&nbsp;<span style="font-weight:600" class="">not</span>&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Comparable</code>&nbsp;types that define an equivalence relation with&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">==</code>&nbsp;will remain unchanged.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">Existing&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Comparable</code>&nbsp;types that define a total ordering with&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">&lt;</code>&nbsp;will need to implement&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">&lt;=&gt;</code>&nbsp;and should remove their existing implementation of any comparison operators, including&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">==</code>. All other existing&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Comparable</code>&nbsp;types should implement&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">&lt;=&gt;</code>&nbsp;that provides a total ordering, or should drop their&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Comparable</code>&nbsp;conformance.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">Before:</p><div style="margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class=""><pre style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;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-break:normal" class=""><span style="color:rgb(167,29,93)" class="">struct</span> Date: <span style="color:rgb(0,134,179)" class="">Comparable</span> {
  <span style="color:rgb(167,29,93)" class="">let</span> year: <span style="color:rgb(0,134,179)" class="">Int</span>
  <span style="color:rgb(167,29,93)" class="">let</span> month: <span style="color:rgb(0,134,179)" class="">Int</span>
  <span style="color:rgb(167,29,93)" class="">let</span> day: <span style="color:rgb(0,134,179)" class="">Int</span>
}

<span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">==</span>(lhs: Date, rhs: Date) <span style="color:rgb(167,29,93)" class="">-&gt;</span> <span style="color:rgb(0,134,179)" class="">Bool</span> {
  <span style="color:rgb(167,29,93)" class="">return</span> lhs<span style="color:rgb(167,29,93)" class="">.</span>year <span style="color:rgb(167,29,93)" class="">==</span> rhs<span style="color:rgb(167,29,93)" class="">.</span>year
    <span style="color:rgb(167,29,93)" class="">&amp;&amp;</span> lhs<span style="color:rgb(167,29,93)" class="">.</span>month <span style="color:rgb(167,29,93)" class="">==</span> rhs<span style="color:rgb(167,29,93)" class="">.</span>month
    <span style="color:rgb(167,29,93)" class="">&amp;&amp;</span> lhs<span style="color:rgb(167,29,93)" class="">.</span>day <span style="color:rgb(167,29,93)" class="">==</span> rhs<span style="color:rgb(167,29,93)" class="">.</span>day
}

<span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">&lt;</span>(lhs: Date, rhs: Date) <span style="color:rgb(167,29,93)" class="">-&gt;</span> <span style="color:rgb(0,134,179)" class="">Bool</span> {
  <span style="color:rgb(167,29,93)" class="">if</span> lhs<span style="color:rgb(167,29,93)" class="">.</span>year <span style="color:rgb(167,29,93)" class="">!=</span> rhs<span style="color:rgb(167,29,93)" class="">.</span>year {
    <span style="color:rgb(167,29,93)" class="">return</span> lhs<span style="color:rgb(167,29,93)" class="">.</span>year <span style="color:rgb(167,29,93)" class="">&lt;</span> rhs<span style="color:rgb(167,29,93)" class="">.</span>year
  } <span style="color:rgb(167,29,93)" class="">else</span> <span style="color:rgb(167,29,93)" class="">if</span> lhs<span style="color:rgb(167,29,93)" class="">.</span>month <span style="color:rgb(167,29,93)" class="">!=</span> rhs<span style="color:rgb(167,29,93)" class="">.</span>month {
    <span style="color:rgb(167,29,93)" class="">return</span> lhs<span style="color:rgb(167,29,93)" class="">.</span>month <span style="color:rgb(167,29,93)" class="">&lt;</span> rhs<span style="color:rgb(167,29,93)" class="">.</span>month
  } <span style="color:rgb(167,29,93)" class="">else</span> {
    <span style="color:rgb(167,29,93)" class="">return</span> lhs<span style="color:rgb(167,29,93)" class="">.</span>day <span style="color:rgb(167,29,93)" class="">&lt;</span> rhs<span style="color:rgb(167,29,93)" class="">.</span>day
  }
}</pre></div><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">After, using the tuple overload of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">&lt;=&gt;</code>:</p><div style="margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class=""><pre style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;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-break:normal" class=""><span style="color:rgb(167,29,93)" class="">struct</span> Date: <span style="color:rgb(0,134,179)" class="">Comparable</span> {
  <span style="color:rgb(167,29,93)" class="">let</span> year: <span style="color:rgb(0,134,179)" class="">Int</span>
  <span style="color:rgb(167,29,93)" class="">let</span> month: <span style="color:rgb(0,134,179)" class="">Int</span>
  <span style="color:rgb(167,29,93)" class="">let</span> day: <span style="color:rgb(0,134,179)" class="">Int</span>

  <span style="color:rgb(167,29,93)" class="">static</span> <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">&lt;=&gt;</span> (lhs: Date, rhs: Date) <span style="color:rgb(167,29,93)" class="">-&gt;</span> Ordering {
    <span style="color:rgb(167,29,93)" class="">return</span> (lhs<span style="color:rgb(167,29,93)" class="">.</span>year, lhs<span style="color:rgb(167,29,93)" class="">.</span>month, lhs<span style="color:rgb(167,29,93)" class="">.</span>day)
       <span style="color:rgb(167,29,93)" class="">&lt;=&gt;</span> (rhs<span style="color:rgb(167,29,93)" class="">.</span>year, rhs<span style="color:rgb(167,29,93)" class="">.</span>month, rhs<span style="color:rgb(167,29,93)" class="">.</span>day)
  }

  <span style="color:rgb(150,152,150)" class="">// // Explicit version:</span>
  <span style="color:rgb(150,152,150)" class="">// static func &lt;=&gt; (lhs: Date, rhs: Date) -&gt; Ordering {</span>
  <span style="color:rgb(150,152,150)" class="">//   let yearResult = lhs.year &lt;=&gt; rhs.year</span>
  <span style="color:rgb(150,152,150)" class="">//   guard case .equal = yearResult else { return yearResult }</span>
  <span style="color:rgb(150,152,150)" class="">//   let monthResult = lhs.month &lt;=&gt; rhs.month</span>
  <span style="color:rgb(150,152,150)" class="">//   guard case .equal = monthResult else { return monthResult }</span>
  <span style="color:rgb(150,152,150)" class="">//   return lhs.day &lt;=&gt; rhs.day</span>
  <span style="color:rgb(150,152,150)" class="">// }</span>
}</pre></div><h2 style="margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class=""><a href="https://github.com/pyrtsa/swift-evolution/blob/ca89e7b3a1dffc99baa695a03544fcba75afd0f3/proposals/NNNN-formalized-ordering.md#alternatives-considered" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank" class=""><u class=""></u><u class=""></u><u class=""></u><u class=""></u></a>Alternatives considered</h2><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">A previous design of this proposal suggested a strict total order upon&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Comparable</code>. While that would make generic algorithms more correct, the definition ended up fighting against the expected behaviour of floating point numbers.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">An alternative design that better matches the existing arithmetic-related protocols in Swift is one that uses a member function.</p><div style="margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class=""><pre style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;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-break:normal" class=""><span style="color:rgb(167,29,93)" class="">public</span> <span style="color:rgb(167,29,93)" class="">protocol</span> <span style="color:rgb(0,134,179)" class="">Comparable</span>: <span style="color:rgb(0,134,179)" class="">Equatable</span> {
  <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">compare</span>(to: <span style="color:rgb(167,29,93)" class="">Self</span>) <span style="color:rgb(167,29,93)" class="">-&gt;</span> Ordering
}</pre></div><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">However, while this API does read better than an operator, we believe that this imposes a number of artificial restrictions (especially in light of&nbsp;<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0091-improving-operators-in-protocols.md" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank" class="">SE-0091</a>)</p><ol style="padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class=""><li class="">There is no way to use&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Comparable.compare</code>&nbsp;as a higher-order function in a non-generic context.</li><li style="margin-top:0.25em" class="">If a member is desired, it can be provided in a protocol extension and defined in terms of the ordering operator; to each according to their need.</li><li style="margin-top:0.25em" class="">The existing tuple overloads cannot be expressed with a member function.</li></ol><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">One other that Rust has adopted is the inclusion of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">PartialEquatable</code>&nbsp;and&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">PartialComparable</code>&nbsp;as ancestors of their flavor of&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Equatable</code>&nbsp;and&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Comparable</code>&nbsp;. Having protocols to organize and catalogue types that can only guarantee partial equivalence and ordering relations is a good approach for modularity but clutters the standard library with two new protocols for which few useful algorithms could be written against.</p><h2 style="margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class=""><a href="https://github.com/pyrtsa/swift-evolution/blob/ca89e7b3a1dffc99baa695a03544fcba75afd0f3/proposals/NNNN-formalized-ordering.md#future-directions" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank" class=""><u class=""></u><u class=""></u><u class=""></u><u class=""></u></a>Future directions</h2><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">That the default&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">sort()</code>&nbsp;compares by&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">&lt;</code>&nbsp;and not&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">&lt;=&gt;</code>&nbsp;should be considered a bug to be fixed in a future version of Swift. Using&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">&lt;=&gt;</code>&nbsp;will make&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">sort()</code>&nbsp;well-behaved in the presense of NaN. However, given that the current behaviour is to produce an unspecified order, the fix is additive and can be slipped past Swift 3.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">With&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">&lt;=&gt;</code>&nbsp;in place, several present and future standard library algorithms involving a&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">&lt;T : Comparable&gt;</code>&nbsp;requirement will possibly benefit from knowing the total ordering of two operands at once. This is a list of possible such functions (taking&nbsp;<code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Array</code>&nbsp;as example), to be proposed separately as an additive change:</p><div style="color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255);margin-bottom:0px!important" class=""><pre style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;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-break:normal" class=""><span style="color:rgb(167,29,93)" class="">extension</span> <span style="color:rgb(0,134,179)" class="">Array</span> {
  <span style="color:rgb(150,152,150)" class="">// Sorting</span>

  <span style="color:rgb(167,29,93)" class="">mutating</span> <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">sort</span>(ordering: <span style="color:rgb(167,29,93)" class="">@noescape</span> (Element, Element) throws <span style="color:rgb(167,29,93)" class="">-&gt;</span> Ordering) rethrows
  <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">sorted</span>(ordering: <span style="color:rgb(167,29,93)" class="">@noescape</span> (Element, Element) throws <span style="color:rgb(167,29,93)" class="">-&gt;</span> Ordering) rethrows -&gt; [Element]
  <span style="color:rgb(167,29,93)" class="">mutating</span> <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">stableSort</span>(ordering: <span style="color:rgb(167,29,93)" class="">@noescape</span> (Element, Element) throws <span style="color:rgb(167,29,93)" class="">-&gt;</span> Ordering) rethrows
  <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">stableSorted</span>(ordering: <span style="color:rgb(167,29,93)" class="">@noescape</span> (Element, Element) throws <span style="color:rgb(167,29,93)" class="">-&gt;</span> Ordering) rethrows -&gt; [Element]

  <span style="color:rgb(150,152,150)" class="">/// Reorders the elements of the collection such that all the elements</span>
  <span style="color:rgb(150,152,150)" class="">/// returning `.ascending` are moved to the start of the collection, and the</span>
  <span style="color:rgb(150,152,150)" class="">/// elements returning `.descending` are moved to the end of the collection.</span>
  <span style="color:rgb(150,152,150)" class="">/// - Returns: the range of elements for which `ordering(x) == .equal`.</span>
  <span style="color:rgb(167,29,93)" class="">mutating</span> <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">partition</span>(ordering: <span style="color:rgb(167,29,93)" class="">@noescape</span> (Iterator<span style="color:rgb(167,29,93)" class="">.</span>Element) throws <span style="color:rgb(167,29,93)" class="">-&gt;</span> Ordering) rethrows -&gt; <span style="color:rgb(0,134,179)" class="">Range</span>&lt;Index&gt;

  <span style="color:rgb(150,152,150)" class="">// Binary search</span>

  <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">bisectedIndex</span>(ordering: <span style="color:rgb(167,29,93)" class="">@noescape</span> (Element) throws <span style="color:rgb(167,29,93)" class="">-&gt;</span> Ordering) rethrows -&gt; Index?
  <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">lowerBound</span>(ordering: <span style="color:rgb(167,29,93)" class="">@noescape</span> (Element) throws <span style="color:rgb(167,29,93)" class="">-&gt;</span> Ordering) rethrows -&gt; Index
  <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">upperBound</span>(ordering: <span style="color:rgb(167,29,93)" class="">@noescape</span> (Element) throws <span style="color:rgb(167,29,93)" class="">-&gt;</span> Ordering) rethrows -&gt; Index
  <span style="color:rgb(167,29,93)" class="">func</span> <span style="color:rgb(121,93,163)" class="">equalRange</span>(ordering: <span style="color:rgb(167,29,93)" class="">@noescape</span> (Element) throws <span style="color:rgb(167,29,93)" class="">-&gt;</span> Ordering) rethrows -&gt; <span style="color:rgb(0,134,179)" class="">Range</span>&lt;Index&gt;
}</pre></div><div class=""><br class=""></div></div></div></div></div></blockquote></div><br class=""></div><br class="">_______________________________________________<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" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
<br class=""></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></body></html>