{"id":17579,"date":"2017-03-31T14:26:01","date_gmt":"2017-03-31T18:26:01","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=17579"},"modified":"2017-03-31T14:47:37","modified_gmt":"2017-03-31T18:47:37","slug":"some-swift-types-are-more-equatable-than-others","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2017\/03\/31\/some-swift-types-are-more-equatable-than-others\/","title":{"rendered":"Some Swift Types Are More Equatable Than Others"},"content":{"rendered":"<p><a href=\"https:\/\/blog.definiteloops.com\/all-types-are-equatable-but-some-are-more-equal-than-others-73a958c01c9b\">Vincent Esche<\/a>:<\/p>\n<blockquote cite=\"https:\/\/blog.definiteloops.com\/all-types-are-equatable-but-some-are-more-equal-than-others-73a958c01c9b\"><p>Now what If I told you that <a href=\"http:\/\/swift.sandbox.bluemix.net\/#\/repl\/58cf28b5c7c0f61c565cc711\">none of these hold true<\/a> for <code>Set&lt;Float&gt;<\/code>, <code>Set&lt;Double&gt;<\/code>, and consequently <code>Set&lt;V&gt;<\/code>?<\/p><p>How can this be, given that both, <code>Float<\/code> and <code>Double<\/code> conform to <code>Hashable<\/code> (and therefor also <code>Equatable<\/code>), one of the (quite literally) key-requirements of <code>Set&lt;Float&gt;<\/code> and <code>Set&lt;Double&gt;<\/code>.<\/p><p>[&#8230;]<\/p><p>Yep, there&rsquo;s indeed more than one <code>NaN<\/code>: a total of <code>8388606<\/code> of them in <code>Float<\/code> alone, to be specific. And even more of them are to be found in <code>Double<\/code>.<\/p><\/blockquote>\n<p>Update (2017-03-31): <a href=\"https:\/\/twitter.com\/jckarter\/status\/847882514223865856\">Joe<\/a> <a href=\"https:\/\/twitter.com\/jckarter\/status\/847882671430680577\">Groff<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/jckarter\/status\/847882514223865856\"><p>There&rsquo;s WIP to make floats Equatable and Comparable using level 2 comparison (so NaN == NaN, NaN &lt; number, -0 != 0)<\/p><\/blockquote>\n<blockquote cite=\"https:\/\/twitter.com\/jckarter\/status\/847882671430680577\"><p>That way you get sound behavior when floats end up in generic containers, but the expected level-1 semantics working concretely with floats.<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Vincent Esche: Now what If I told you that none of these hold true for Set&lt;Float&gt;, Set&lt;Double&gt;, and consequently Set&lt;V&gt;?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&lt;Float&gt; and Set&lt;Double&gt;.[&#8230;]Yep, there&rsquo;s indeed more than one NaN: a total of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[669,46,71,901],"class_list":["post-17579","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-floating-point","tag-languagedesign","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/17579","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=17579"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/17579\/revisions"}],"predecessor-version":[{"id":17583,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/17579\/revisions\/17583"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=17579"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=17579"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=17579"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}