Some Swift Types Are More Equatable Than Others
Now what If I told you that none of these hold true for
Set<Float>
,Set<Double>
, and consequentlySet<V>
?How can this be, given that both,
Float
andDouble
conform toHashable
(and therefor alsoEquatable
), one of the (quite literally) key-requirements ofSet<Float>
andSet<Double>
.[…]
Yep, there’s indeed more than one
NaN
: a total of8388606
of them inFloat
alone, to be specific. And even more of them are to be found inDouble
.
Update (2017-03-31): Joe Groff:
There’s WIP to make floats Equatable and Comparable using level 2 comparison (so NaN == NaN, NaN < number, -0 != 0)
That way you get sound behavior when floats end up in generic containers, but the expected level-1 semantics working concretely with floats.