From 25f2c8506639cdeb7be55879b7e9aa432b8be265 Mon Sep 17 00:00:00 2001 From: akr Date: Sat, 30 Apr 2016 11:18:00 +0000 Subject: Define Integer#== instead of Bignum#==. * numeric.c (int_equal): Define Integer#==. * bignum.c (rb_big_eq): Don't define Bignum#==. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ bignum.c | 1 - numeric.c | 20 ++++++++++++++++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1ec8485df8..f9665d592a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sat Apr 30 20:17:08 2016 Tanaka Akira + + * numeric.c (int_equal): Define Integer#==. + + * bignum.c (rb_big_eq): Don't define Bignum#==. + Sat Apr 30 19:41:15 2016 Tanaka Akira * numeric.c (int_gt): Define Integer#>. diff --git a/bignum.c b/bignum.c index ea2931b80f..14c8ec8f45 100644 --- a/bignum.c +++ b/bignum.c @@ -6848,7 +6848,6 @@ Init_Bignum(void) rb_define_method(rb_cBignum, "/", rb_big_div, 1); rb_define_method(rb_cBignum, "%", rb_big_modulo, 1); - rb_define_method(rb_cBignum, "==", rb_big_eq, 1); rb_define_method(rb_cBignum, "===", rb_big_eq, 1); #ifdef USE_GMP diff --git a/numeric.c b/numeric.c index 5c3bc2912f..50c13b8659 100644 --- a/numeric.c +++ b/numeric.c @@ -3747,11 +3747,14 @@ rb_int_pow(VALUE x, VALUE y) } /* + * Document-method: Integer#== * Document-method: Fixnum#== * call-seq: - * fix == other -> true or false + * int == other -> true or false * - * Return +true+ if +fix+ equals +other+ numerically. + * Return +true+ if +int+ equals +other+ numerically. + * Contrast this with Integer#eql?, which + * requires other to be a Integer. * * 1 == 2 #=> false * 1 == 1.0 #=> true @@ -3773,6 +3776,18 @@ fix_equal(VALUE x, VALUE y) } } +static VALUE +int_equal(VALUE x, VALUE y) +{ + if (FIXNUM_P(x)) { + return fix_equal(x, y); + } + else if (RB_TYPE_P(x, T_BIGNUM)) { + return rb_big_eq(x, y); + } + return Qnil; +} + /* * Document-method: Integer#<=> * call-seq: @@ -4937,6 +4952,7 @@ Init_Numeric(void) rb_define_method(rb_cInteger, "abs", int_abs, 0); rb_define_method(rb_cInteger, "magnitude", int_abs, 0); + rb_define_method(rb_cInteger, "==", int_equal, 1); rb_define_method(rb_cInteger, ">", int_gt, 1); rb_define_method(rb_cInteger, ">=", int_ge, 1); rb_define_method(rb_cInteger, "<", int_lt, 1); -- cgit v1.2.3