From 295113337299ac92eee3895c15a13de3372cfee0 Mon Sep 17 00:00:00 2001 From: akr Date: Sat, 30 Apr 2016 12:39:53 +0000 Subject: 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#/. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54851 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- numeric.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'numeric.c') diff --git a/numeric.c b/numeric.c index 8214873fc1..3923b4139b 100644 --- a/numeric.c +++ b/numeric.c @@ -3421,9 +3421,10 @@ int_fdiv(VALUE x, VALUE y) } /* + * 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) 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) 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); -- cgit v1.2.3