summaryrefslogtreecommitdiff
path: root/ext/bigdecimal
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-01 13:20:22 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-01 13:20:22 +0000
commit98685cc70fd4ea86bccc81983283c29eb7b2afd7 (patch)
tree0006f6a4e9833bbea199551b3c9d0bbefc564ce9 /ext/bigdecimal
parentc29b801afad1dc5cb4227bcef9e4bc004c967b8a (diff)
* ext/bigdecimal/bigdecimal.c (BigDecimal_hash): use rb_memhash and take care of negative finite numbers properly.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28825 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal')
-rw-r--r--ext/bigdecimal/bigdecimal.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 146145ce419..239fe05a762 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -228,12 +228,9 @@ BigDecimal_hash(VALUE self)
GUARD_OBJ(p,GetVpValue(self,1));
hash = (U_LONG)p->sign;
/* hash!=2: the case for 0(1),NaN(0) or +-Infinity(3) is sign itself */
- if(hash==2) {
- for(i = 0; i < p->Prec;i++) {
- hash = 31 * hash + p->frac[i];
- hash ^= p->frac[i];
- }
- hash += p->exponent;
+ if(hash == 2 || hash == -2) {
+ hash ^= rb_memhash(p->frac, sizeof(U_LONG)*p->Prec);
+ hash += p->exponent;
}
return INT2FIX(hash);
}