Friday, March 31, 2017

Some Swift Types Are More Equatable Than Others

Vincent Esche:

Now what If I told you that none of these hold true for Set<Float>, Set<Double>, and consequently Set<V>?

How can this be, given that both, Float and Double conform to Hashable (and therefor also Equatable), one of the (quite literally) key-requirements of Set<Float> and Set<Double>.


Yep, there’s indeed more than one NaN: a total of 8388606 of them in Float alone, to be specific. And even more of them are to be found in Double.

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.

Comments RSS · Twitter

Leave a Comment