> On Oct 20, 2017, at 07:51, Xiaodi Wu via swift-dev <swift-dev@swift.org>
> wrote:
>
> On Fri, Oct 20, 2017 at 1:22 AM, Jonathan Hull <jh...@gbis.com
> <mailto:jh...@gbis.com>> wrote:
> +1 for trapping unless using &==. In the case of ‘Float?’ we could also map
> to nil.
>
> This is probably a more appropriate discussion for evolution though...
>
>
>> On Oct 19, 2017, at 9:48 PM, Brent Royal-Gordon via swift-dev
>> <swift-dev@swift.org <mailto:swift-dev@swift.org>> wrote:
>>
>>> On Oct 19, 2017, at 4:29 PM, Xiaodi Wu via swift-dev <swift-dev@swift.org
>>> <mailto:swift-dev@swift.org>> wrote:
>>>
>>> D) Must floating-point IEEE-compliant equivalence be spelled `==`?
>>>
>>> In my view, this is something open for debate. I see no reason why it
>>> cannot be migrated to `&==` if it were felt that `==` *must* be a full
>>> equivalence relation. I believe this is controversial, however.
>>
>> I actually got partway through writing up a pitch on this yesterday, but my
>> opinion is that NaNs are so exceptional, and so prone to misuse, that we
>> ought to treat them like integer arithmetic overflows: trap when they're
>> detected, unless you use an `&` variant operator which indicates you know
>> what you're doing.
>>
>> I strongly suspect that, in practice, most float-manipulating code is not
>> prepared to handle NaN and will not do anything sensible in its presence.
>> For example, Apple platforms use floating-point types for geometry, color
>> components, GPS locations, etc. Very little of this code will do anything
>> sensible in the presence of a NaN. Arguably, it'd be better to exclude them
>> through the type system, but I don't think that's a realistic possibility—we
>> would need to have done that in a more source-break-friendly era. But that
>> doesn't have to mean we're completely stuck.
>
>
> Built-in floating point operators, as well as libc/libm math functions, are
> designed to propagate NaN correctly. This is not meant to be a thread about
> NaN, and we need to be cautious to define the scope of the problem to be
> solved from the outset. The tendency of having ever-expanding discussion
> where issues such as method names turn into discussions about the entire
> standard library go nowhere.
>
> The question here is about `==` specifically and how to accommodate partial
> equivalence relations. For sanity, we start with the premise that NaN will
> forever be as it is.
I support Jonathan’s argument. If Swift wants to trap on NaN to improve
self-consistency and simplicity, then the tradeoff might be worth it. The
alternative, teaching the Equality protocol about NaNs, feels like “the tail
wagging the dog".
In short: what IEEE requires of floating-point hardware is separable from
IEEE’s opinions about language/library design.
Dave
_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev