ruby-changes:42777
From: akr <ko1@a...>
Date: Sat, 30 Apr 2016 20:43:17 +0900 (JST)
Subject: [ruby-changes:42777] akr:r54851 (trunk): Define Integer#/ instead of Bignum#/.
akr 2016-04-30 21:39:53 +0900 (Sat, 30 Apr 2016) New Revision: 54851 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54851 Log: Define Integer#/ instead of Bignum#/. * numeric.c (rb_int_div): Define Integer#/. * bignum.c (rb_big_div): Don't define Bignum#/. * lib/mathn.rb (Integer#/): Replace Integer#/ instead of Bignum#/. Modified files: trunk/ChangeLog trunk/bignum.c trunk/lib/mathn.rb trunk/numeric.c Index: ChangeLog =================================================================== --- ChangeLog (revision 54850) +++ ChangeLog (revision 54851) @@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Apr 30 21:28:14 2016 Tanaka Akira <akr@f...> + + * numeric.c (rb_int_div): Define Integer#/. + + * bignum.c (rb_big_div): Don't define Bignum#/. + + * lib/mathn.rb (Integer#/): Replace Integer#/ instead of Bignum#/. + Sat Apr 30 21:11:08 2016 Tanaka Akira <akr@f...> * numeric.c (rb_int_plus): Define Integer#+. Index: lib/mathn.rb =================================================================== --- lib/mathn.rb (revision 54850) +++ lib/mathn.rb (revision 54851) @@ -79,7 +79,7 @@ end https://github.com/ruby/ruby/blob/trunk/lib/mathn.rb#L79 # # (2**72) / ((2**70) * 3) # => 4/3 -class Bignum +class Integer remove_method :/ ## Index: numeric.c =================================================================== --- numeric.c (revision 54850) +++ numeric.c (revision 54851) @@ -3421,9 +3421,10 @@ int_fdiv(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3421 } /* + * Document-method: Integer#/ * Document-method: Fixnum#/ * call-seq: - * fix / numeric -> numeric_result + * int / numeric -> numeric_result * * Performs division: the class of the resulting object depends on the class of * +numeric+ and on the magnitude of the result. It may return a Bignum. @@ -3469,6 +3470,18 @@ fix_div(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3470 return fix_divide(x, y, '/'); } +VALUE +rb_int_div(VALUE x, VALUE y) +{ + if (FIXNUM_P(x)) { + return fix_div(x, y); + } + else if (RB_TYPE_P(x, T_BIGNUM)) { + return rb_big_div(x, y); + } + return Qnil; +} + /* * Document-method: Integer#div * call-seq: @@ -4947,6 +4960,7 @@ Init_Numeric(void) https://github.com/ruby/ruby/blob/trunk/numeric.c#L4960 rb_define_method(rb_cFixnum, "*", fix_mul, 1); rb_define_method(rb_cInteger, "*", rb_int_mul, 1); rb_define_method(rb_cFixnum, "/", fix_div, 1); + rb_define_method(rb_cInteger, "/", rb_int_div, 1); rb_define_method(rb_cInteger, "div", rb_int_idiv, 1); rb_define_method(rb_cFixnum, "%", fix_mod, 1); rb_define_method(rb_cInteger, "%", rb_int_modulo, 1); Index: bignum.c =================================================================== --- bignum.c (revision 54850) +++ bignum.c (revision 54851) @@ -6038,15 +6038,6 @@ rb_big_divide(VALUE x, VALUE y, ID op) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6038 return bignorm(z); } -/* - * call-seq: - * big / other -> Numeric - * - * Performs division: the class of the resulting object depends on - * the class of <code>numeric</code> and on the magnitude of the - * result. - */ - VALUE rb_big_div(VALUE x, VALUE y) { @@ -6821,7 +6812,6 @@ Init_Bignum(void) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6812 rb_cBignum = rb_define_class("Bignum", rb_cInteger); rb_define_method(rb_cBignum, "coerce", rb_big_coerce, 1); - rb_define_method(rb_cBignum, "/", rb_big_div, 1); rb_define_method(rb_cBignum, "===", rb_big_eq, 1); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/