|At Wed, 8 Apr 2009 14:38:31 +0900,
|Heesob Park wrote in [ruby-core:23154]:
|> Ruby cannot handle NaN as a unique key of Hash.
|
|It's easy to make them unique as key, I'm not sure which is
|"correct" behavior though.
Two NaN values are not equal with each other by definition, in that
sense, even though some might want to use NaN as a hash key, the
current behavior seems to be "correct".
|At Wed, 8 Apr 2009 14:38:31 +0900,
|Heesob Park wrote in [ruby-core:23154]:
|> Ruby cannot handle NaN as a unique key of Hash.
|
|It's easy to make them unique as key, I'm not sure which is
|"correct" behavior though.
Two NaN values are not equal with each other by definition, in that
sense, even though some might want to use NaN as a hash key, the
current behavior seems to be "correct".
I don't argue about correctness on NaNs being different each other, but I also
agree with the reporter with Hash being inconvenient when NaNs used as keys.
|I don't argue about correctness on NaNs being different each other, but I also
|agree with the reporter with Hash being inconvenient when NaNs used as keys.
Using float values as hash keys should be strongly discouraged,
because you may not have expected result anyway. a 3.14 may be
different in bit-wise representation from another 3.14. I have no
plan to prohibit using them as keys, right now, but see no need to
change the language to encourage bad habit. If I have to make a
change related to this issue, I'd rather prohibit NaN as a key (or
float keys in general), as in [ruby-core:23426].
The behavior OP reported is not a bug. So I close the ticket.
Indeed, the behavior is confusing a little.
IMO, it would be good to warn when Float is used as hash keys.
Anyway, warning or prohibiting NaN is a new feature, not bug
fix for this ticket. If you still want, please register a
new ticket to Feature tracker.