[swift-evolution] [Draft][Proposal] Formalized Ordering

Dmitri Gribenko gribozavr at gmail.com
Fri Jul 22 00:37:24 CDT 2016


On Thu, Jul 21, 2016 at 10:17 PM, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
> Robert, the gist is notably vague on this point, so I'm hoping you will
> clarify. Are you proposing that FloatingPoint will break with IEEE754
> semantics? What will be the result of `Float.nan == Float.nan`?
>
> (My guess at the sanest outcome is that areSame/Equivalent() and <=> will be
> totally ordered but FloatingPoint types will override == and the standard
> comparison operators to maintain IEEE754 semantics, yes?)

Right, == (and !=, <, >, <=, >=) can be customized with
domain-specific semantics, and floating point does this.  In addition,
floating point protocols will list == as a requirement, so generic
code generic over floating point types will get IEEE 754 semantics
when using == syntax, but code that only has an Equatable requirement
will use the total ordering semantics.

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/


More information about the swift-evolution mailing list