diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2022-08-31 11:01:59 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2022-09-02 14:33:23 +0900 |
commit | 9212d963070612e669c40e5fde7954f19d648002 (patch) | |
tree | edffc38b5c9350989e767fcb0059bf04203c9f1d /complex.c | |
parent | a9b59e24f49f669f6ad2f3238c4c518027a7f72d (diff) |
[Bug #18937] Coerce non-real non-Numeric into Complex at comparisons
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/6317
Diffstat (limited to 'complex.c')
-rw-r--r-- | complex.c | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -1124,15 +1124,23 @@ nucomp_cmp(VALUE self, VALUE other) if (!k_numeric_p(other)) { return rb_num_coerce_cmp(self, other, idCmp); } - if (nucomp_real_p(self)) { - if (RB_TYPE_P(other, T_COMPLEX) && nucomp_real_p(other)) { + if (!nucomp_real_p(self)) { + return Qnil; + } + if (RB_TYPE_P(other, T_COMPLEX)) { + if (nucomp_real_p(other)) { get_dat2(self, other); return rb_funcall(adat->real, idCmp, 1, bdat->real); } - else if (f_real_p(other)) { - get_dat1(self); + } + else { + get_dat1(self); + if (f_real_p(other)) { return rb_funcall(dat->real, idCmp, 1, other); } + else { + return rb_num_coerce_cmp(dat->real, other, idCmp); + } } return Qnil; } |