aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-30 12:39:53 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-30 12:39:53 +0000
commit8248c26e6dfb2d80c03c65ca51bca62992e5c959 (patch)
treec9e50313b28ebed27525b91497ab9a1698f6639a
parentd0e2d150b8bc9d18d2beff1752086237a627b509 (diff)
downloadruby-8248c26e6dfb2d80c03c65ca51bca62992e5c959.tar.gz
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
-rw-r--r--ChangeLog8
-rw-r--r--bignum.c10
-rw-r--r--lib/mathn.rb2
-rw-r--r--numeric.c16
4 files changed, 24 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 731ff9d632..4665105e5a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Sat Apr 30 21:28:14 2016 Tanaka Akira <akr@fsij.org>
+
+ * 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@fsij.org>
* numeric.c (rb_int_plus): Define Integer#+.
diff --git a/bignum.c b/bignum.c
index 1355ec0d1d..3c6a85a984 100644
--- a/bignum.c
+++ b/bignum.c
@@ -6038,15 +6038,6 @@ rb_big_divide(VALUE x, VALUE y, ID op)
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)
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);
diff --git a/lib/mathn.rb b/lib/mathn.rb
index d07388bc26..9e33f45580 100644
--- a/lib/mathn.rb
+++ b/lib/mathn.rb
@@ -79,7 +79,7 @@ end
#
# (2**72) / ((2**70) * 3) # => 4/3
-class Bignum
+class Integer
remove_method :/
##
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);