Issue #22452 has been updated by matz (Yukihiro Matsumoto). I don't consider this a bug. The identity shortcut in `rb_equal` is intentional, and many collection operations rely on it. As concluded in #1720, the result of comparing NaN is implementation dependent, including how NaN is treated in collections. I don't want to slow down `rb_equal` for the sake of NaN. It may be worth documenting that methods like `Array#index` can treat the same NaN object as equal to itself. Matz. ---------------------------------------- Bug #22452: `rb_equal` returns true for `NaN == NaN` https://bugs.ruby-lang.org/issues/22452#change-120129 * Author: byroot (Jean Boussier) * Status: Open * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- I noticed this while trying to cleanup and simplify `rb_equal`. ```ruby
Float::NAN == Float::NAN => false [Float::NAN].index(Float::NAN) => 0
I would expect it to return `nil`.
`Array#index` is just an example, any core method, and even C extension relying on `rb_equal` is similarly impacted.
This bug is present on all Ruby versions, except for versions between 2.1 and 2.4.
The bug seem to have been re-introduced in 2.5 by [6e0e067de31511cebec01d176f628442371db879](https://github.com/ruby/ruby/commit/6e0e067de31511cebec01d176f628442371db879)
JRuby seem to have the same behavior, but TruffleRuby correctly returns`nil`.
--
https://bugs.ruby-lang.org/