<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 24, 2017, at 11:52 PM, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">On Tue, Apr 25, 2017 at 12:45 AM, Jonathan Hull via swift-evolution<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;">+1<br class=""><br class="">What I am arguing for is #2. We have two different expectations and we need to be explicit about which is being used. Furthermore, I am arguing that if one of them is going to be the default (and use the ‘==‘ and ‘<‘ symbols), it needs to be the strict equality/total ordering version, since that is what every other Swift type is modeling, and IEEE is only applicable to floating point.<br class=""></blockquote><div class=""><br class=""></div><div class="">Then it's an insoluble problem, because (and for good reasons) there are those who consider anything other than `.nan != .nan` to be a non-starter. My attempt to convince people that maybe we could just make that expression trap instead of giving an answer did not, evidently, win over too many fans. But I tend to sympathize with the numerics crowd that `.nan == .nan` would be disastrous for Swift when it comes to numerics. No other (common) language behaves that way.</div></div></div></div></div></blockquote><div><br class=""></div><div>Java’s solution is to only support comparison operators for native types like floats and doubles, and to have the IEEE behavior for these types. The java.lang.Comparable interface does not expose operators, and thus does not have a naming conflict. The Comparable implementation for Float has strict total ordering, while ‘<‘ has IEEE behavior.</div><div><br class=""></div><div>So I think a sixth option I didn’t propose before. If we were pre Swift 3 it would possibly be the more feasible one:</div><div><br class=""></div><div>6. Do not define Equatable/Comparable in terms of the existing operators, and do not expose existing operators based on Equatable/Comparable. Instead, Equatable/Comparable define methods or new operators based on strict equality/total ordering. Conformance to some other sub-protocol like StrictlyEquatable/StrictlyComparable is used to opt into exposing operators based on implementing strict equality and total ordering.</div><div><br class=""></div><div>This would mean that Equatable/Comparable generic algorithms are forced to always use total ordering algorithms without the chance of having a conflict with floating point operators - because the naming no longer conflicts.</div><div><br class=""></div><div>-DW</div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div class="HOEnZb"><div class="h5">> On Apr 24, 2017, at 9:44 PM, David Waite via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class="">><br class="">> I still think this is a naming conflict more than anything else.<br class="">><br class="">> The first expectation is that equatable and comparable provides strict equality and strict total ordering, and that those are exposed via operators. The other expectation is that floating point abides by the IEEE rules which have neither of these, and are exposed via operators.<br class="">><br class="">> Either:<br class="">> 1. the operators need to do different things in different contexts<br class="">> 2. we need different methods/operators to indicate these different concepts<br class="">> 3. Equatable and comparable need to be altered to no longer require strict equality and strict total ordering (and all generic algorithms based on equatable/comparable need to be checked that they still work)<br class="">> 4. floating point numbers need to explicitly not be equatable/comparable to prevent their usage in generic algorithms requiring strict behavior.<br class="">> 5. We break away from IEEE behavior and provide only strict equality and strict total ordering<br class="">><br class="">> (I tried to sort these roughly in order of feasibility)<br class="">><br class="">> Are there any other options?<br class="">><br class="">> -DW<br class="">><br class="">>> On Apr 24, 2017, at 9:50 PM, Dave Abrahams via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class="">>><br class="">>><br class="">>> on Mon Apr 24 2017, Xiaodi Wu <<a href="http://xiaodi.wu-at-gmail.com/" rel="noreferrer" target="_blank" class="">xiaodi.wu-AT-gmail.com</a>> wrote:<br class="">>><br class="">>>> On Mon, Apr 24, 2017 at 9:06 PM, Jonathan Hull via swift-evolution <<br class="">>>><span class="Apple-converted-space"> </span><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class="">>>><br class="">>>>> As I am thinking about it more, this means that for == and <<br class="">>>>><br class="">>>>> NaN == NaN<br class="">>>>> -0 == +0<br class="">>>>> +Inf < NaN<br class="">>>>><br class="">>>>> Since this would break from IEEE,<br class="">>>><br class="">>>> Yeah, as Steve mentioned, it's a huge deal to break from IEEE rules.<br class="">>><br class="">>> Allow me to put it even more strongly: I consider reinventing how<br class="">>> floating point works to be a massive undertaking comparable to<br class="">>> supplanting the Unicode standard with something better. I have no doubt<br class="">>> that it could be done by somebody, somewhere, someday, but it would be<br class="">>> easy to do something much worse than what IEEE has done, and getting it<br class="">>> right would occupy so much of this group's time that we couldn't hope to<br class="">>> accomplish anything else, if we even had the expertise—I know I don't!<br class="">>> Doing anything in this area that is not firmly rooted in existing<br class="">>> standards and practices is not an option I'm willing to pursue.<br class="">>><br class="">>> --<br class="">>> -Dave<br class="">>> ______________________________<wbr class="">_________________<br class="">>> swift-evolution mailing list<br class="">>><span class="Apple-converted-space"> </span><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">>><span class="Apple-converted-space"> </span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-<wbr class="">evolution</a><br class="">><br class="">> ______________________________<wbr class="">_________________<br class="">> swift-evolution mailing list<br class="">><span class="Apple-converted-space"> </span><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">><span class="Apple-converted-space"> </span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-<wbr class="">evolution</a><br class=""><br class="">______________________________<wbr 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/<wbr class="">mailman/listinfo/swift-<wbr class="">evolution</a></div></div></blockquote></div></div></div></div></blockquote></div><br class=""></body></html>