<story><title>Go 1.21 may have a clear(x) builtin</title><url>https://utcc.utoronto.ca/~cks/space/blog/programming/GoFutureClearBuiltin</url></story><parent_chain><item><author>bobbylarrybobby</author><text>Using floats as hash keys is insane, no?</text></item><item><author>derriz</author><text>Java has a specific hack for this which I discovered by accident a few years ago.  Normally, given (primitive) double values d0 and d1, then boxing them does not affect equality testing - i.e. d0 == d1 if and only if Double.valueOf(d0).equals(Double.valueOf(d1)).  However if d0 and d1 are both NaN, then the boxed versions ARE considered equal while d0 == d1 is false.&lt;p&gt;This inconsistency infuriated me when I discovered it but the Javadoc for Double.equals explicitly states that this anomaly is there to &amp;quot;allow hash tables to work properly&amp;quot;.</text></item></parent_chain><comment><author>zbentley</author><text>Not at all.&lt;p&gt;If I get floats from $somewhere, I might want to index them into a hash data structure without creating a huge sparse array.&lt;p&gt;If you assume float numbers have &amp;quot;identity&amp;quot; such that, whatever the precision, &amp;quot;x == x&amp;quot; always holds (other than NaN), then this is a perfectly valid thing to want.</text></comment>
<story><title>Go 1.21 may have a clear(x) builtin</title><url>https://utcc.utoronto.ca/~cks/space/blog/programming/GoFutureClearBuiltin</url></story><parent_chain><item><author>bobbylarrybobby</author><text>Using floats as hash keys is insane, no?</text></item><item><author>derriz</author><text>Java has a specific hack for this which I discovered by accident a few years ago.  Normally, given (primitive) double values d0 and d1, then boxing them does not affect equality testing - i.e. d0 == d1 if and only if Double.valueOf(d0).equals(Double.valueOf(d1)).  However if d0 and d1 are both NaN, then the boxed versions ARE considered equal while d0 == d1 is false.&lt;p&gt;This inconsistency infuriated me when I discovered it but the Javadoc for Double.equals explicitly states that this anomaly is there to &amp;quot;allow hash tables to work properly&amp;quot;.</text></item></parent_chain><comment><author>bushbaba</author><text>Not if you’re hash table is designed to accommodate key conflicts, and the float is deterministic.</text></comment>