From: Nobuyoshi Nakada Date: 2009-05-11T19:03:59+09:00 Subject: [ruby-core:23423] Re: [Bug #1363] Wrong value for Hash of NaN Hi, 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. > I think this is related with the NaN comparing problem: > > irb(main):001:0> 0/0.0 == 0/0.0 > => false > irb(main):002:0> a = 0/0.0 > => NaN > irb(main):003:0> a == a > => false > irb(main):004:0> a <=> a > => nil I think it's mathematically correct behavior, and different thing from Hash. Index: numeric.c =================================================================== --- numeric.c (revision 23390) +++ numeric.c (working copy) @@ -1127,7 +1127,6 @@ flo_eql(VALUE x, VALUE y) double a = RFLOAT_VALUE(x); double b = RFLOAT_VALUE(y); -#if defined(_MSC_VER) && _MSC_VER < 1300 - if (isnan(a) || isnan(b)) return Qfalse; -#endif + if (isnan(a) && isnan(b)) + return memcmp(&a, &b, sizeof(a)) ? Qfalse : Qtrue; if (a == b) return Qtrue; -- Nobu Nakada