ruby-changes:42760
From: akr <ko1@a...>
Date: Sat, 30 Apr 2016 13:09:17 +0900 (JST)
Subject: [ruby-changes:42760] akr:r54834 (trunk): {Fixnum, Bignum}#divmod is unified into Integer.
akr 2016-04-30 14:05:54 +0900 (Sat, 30 Apr 2016) New Revision: 54834 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54834 Log: {Fixnum,Bignum}#divmod is unified into Integer. * numeric.c (int_divmod): {Fixnum,Bignum}#divmod is unified into Integer. * bignum.c (rb_big_divmod): Don't define Bignum#divmod. Modified files: trunk/ChangeLog trunk/bignum.c trunk/numeric.c Index: numeric.c =================================================================== --- numeric.c (revision 54833) +++ numeric.c (revision 54834) @@ -3536,11 +3536,11 @@ rb_int_modulo(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3536 } /* - * Document-method: Fixnum#divmod + * Document-method: Integer#divmod * call-seq: - * fix.divmod(numeric) -> array + * integer.divmod(numeric) -> array * - * See Numeric#divmod. + * See <code>Numeric#divmod</code>. */ static VALUE fix_divmod(VALUE x, VALUE y) @@ -3571,6 +3571,18 @@ fix_divmod(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3571 } } +static VALUE +int_divmod(VALUE x, VALUE y) +{ + if (FIXNUM_P(x)) { + return fix_divmod(x, y); + } + else if (RB_TYPE_P(x, T_BIGNUM)) { + return rb_big_divmod(x, y); + } + return Qnil; +} + /* * Document-method: Integer#** * call-seq: @@ -4830,7 +4842,7 @@ Init_Numeric(void) https://github.com/ruby/ruby/blob/trunk/numeric.c#L4842 rb_define_method(rb_cFixnum, "div", fix_idiv, 1); rb_define_method(rb_cFixnum, "%", fix_mod, 1); rb_define_method(rb_cFixnum, "modulo", fix_mod, 1); - rb_define_method(rb_cFixnum, "divmod", fix_divmod, 1); + rb_define_method(rb_cInteger, "divmod", int_divmod, 1); rb_define_method(rb_cInteger, "fdiv", int_fdiv, 1); rb_define_method(rb_cInteger, "**", rb_int_pow, 1); Index: bignum.c =================================================================== --- bignum.c (revision 54833) +++ bignum.c (revision 54834) @@ -6176,13 +6176,6 @@ rb_big_remainder(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6176 return bignorm(z); } -/* - * call-seq: - * big.divmod(numeric) -> array - * - * See <code>Numeric#divmod</code>. - * - */ VALUE rb_big_divmod(VALUE x, VALUE y) { @@ -6920,7 +6913,6 @@ Init_Bignum(void) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6913 rb_define_method(rb_cBignum, "/", rb_big_div, 1); rb_define_method(rb_cBignum, "%", rb_big_modulo, 1); rb_define_method(rb_cBignum, "div", rb_big_idiv, 1); - rb_define_method(rb_cBignum, "divmod", rb_big_divmod, 1); rb_define_method(rb_cBignum, "modulo", rb_big_modulo, 1); rb_define_method(rb_cBignum, "remainder", rb_big_remainder, 1); Index: ChangeLog =================================================================== --- ChangeLog (revision 54833) +++ ChangeLog (revision 54834) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Apr 30 14:04:30 2016 Tanaka Akira <akr@f...> + + * numeric.c (int_divmod): {Fixnum,Bignum}#divmod is unified into + Integer. + + * bignum.c (rb_big_divmod): Don't define Bignum#divmod. + Sat Apr 30 13:20:00 2016 Tanaka Akira <akr@f...> * numeric.c (int_fdiv): {Fixnum,Bignum}#fdiv is unified into -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/