summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-28 00:54:19 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-28 00:54:19 +0000
commited737b87d46521e5bf082138f251eb3018966821 (patch)
tree57417318d6f1a03dcf075e15920c113eadf318a3 /hash.c
parent3a312317e68a8365edbd71cda5729c3d08d27bbb (diff)
merge revision(s) 49999,50000: [Backport #10979]
* hash.c (rb_any_hash): use same hash values with Float#hash so that -0.0 and +0.0 will be identical. [ruby-core:68541] [Bug #10979] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@50655 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/hash.c b/hash.c
index 376f33f1ac..75ecdc0fe4 100644
--- a/hash.c
+++ b/hash.c
@@ -133,11 +133,18 @@ rb_any_hash(VALUE a)
if (SPECIAL_CONST_P(a)) {
if (a == Qundef) return 0;
+ if (FLONUM_P(a)) {
+ /* prevent pathological behavior: [Bug #10761] */
+ return rb_dbl_hash(rb_float_value(a));
+ }
hnum = rb_objid_hash((st_index_t)a);
}
else if (BUILTIN_TYPE(a) == T_STRING) {
hnum = rb_str_hash(a);
}
+ else if (BUILTIN_TYPE(a) == T_FLOAT) {
+ return rb_dbl_hash(rb_float_value(a));
+ }
else {
hval = rb_hash(a);
hnum = FIX2LONG(hval);