summaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2021-05-07 12:49:32 +0900
committer卜部昌平 <shyouhei@ruby-lang.org>2021-05-12 10:30:46 +0900
commitcc0dc67bbbe1951ff90004bc987f78545625d772 (patch)
treeb6bf1c68d335875409ecd96bf56ef6e5dec64f92 /compile.c
parentd0e6c6e682b9ba2b0309a5177933a0628e8ef316 (diff)
cdhash_cmp: can also take complex
There are complex literals `123i`, which can also be a case condition.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4469
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/compile.c b/compile.c
index 341361dc78..d9894d27d8 100644
--- a/compile.c
+++ b/compile.c
@@ -2005,10 +2005,15 @@ cdhash_cmp(VALUE val, VALUE lit)
else if (tlit == T_FLOAT) {
return rb_float_cmp(lit, val);
}
- else if (tlit == T_RATIONAL) {
- const struct RRational *dat1 = RRATIONAL(val);
- const struct RRational *dat2 = RRATIONAL(lit);
- return (dat1->num == dat2->num) && (dat1->den == dat2->den);
+ else if (tlit == T_RATIONAL) {
+ const struct RRational *rat1 = RRATIONAL(val);
+ const struct RRational *rat2 = RRATIONAL(lit);
+ return (rat1->num == rat2->num) && (rat1->den == rat2->den);
+ }
+ else if (tlit == T_COMPLEX) {
+ const struct RComplex *comp1 = RCOMPLEX(val);
+ const struct RComplex *comp2 = RCOMPLEX(lit);
+ return (comp1->real == comp2->real) && (comp1->imag == comp2->imag);
}
else {
UNREACHABLE_RETURN(-1);
@@ -2030,6 +2035,8 @@ cdhash_hash(VALUE a)
return rb_dbl_long_hash(RFLOAT_VALUE(a));
case T_RATIONAL:
return rb_rational_hash(a);
+ case T_COMPLEX:
+ return rb_complex_hash(a);
default:
UNREACHABLE_RETURN(0);
}