[前][次][番号順一覧][スレッド一覧]

ruby-changes:42758

From: akr <ko1@a...>
Date: Sat, 30 Apr 2016 12:24:20 +0900 (JST)
Subject: [ruby-changes:42758] akr:r54832 (trunk): {Fixnum, Bignum}#fdiv is unified into Integer.

akr	2016-04-30 13:20:56 +0900 (Sat, 30 Apr 2016)

  New Revision: 54832

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54832

  Log:
    {Fixnum,Bignum}#fdiv is unified into Integer.
    
    * numeric.c (int_fdiv): {Fixnum,Bignum}#fdiv is unified into
      Integer.
    
    * bignum.c (rb_big_fdiv): Don't define Bignum#fdiv.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c
    trunk/numeric.c
Index: bignum.c
===================================================================
--- bignum.c	(revision 54831)
+++ bignum.c	(revision 54832)
@@ -6254,19 +6254,6 @@ big_fdiv_float(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6254
     return big_fdiv(x, y, i - DBL_MANT_DIG);
 }
 
-/*
- *  call-seq:
-  *     big.fdiv(numeric) -> float
- *
- *  Returns the floating point result of dividing <i>big</i> by
- *  <i>numeric</i>.
- *
- *     -1234567890987654321.fdiv(13731)      #=> -89910996357705.5
- *     -1234567890987654321.fdiv(13731.24)   #=> -89909424858035.7
- *
- */
-
-
 VALUE
 rb_big_fdiv(VALUE x, VALUE y)
 {
@@ -6936,7 +6923,6 @@ Init_Bignum(void) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6923
     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);
-    rb_define_method(rb_cBignum, "fdiv", rb_big_fdiv, 1);
 
     rb_define_method(rb_cBignum, "==", rb_big_eq, 1);
     rb_define_method(rb_cBignum, ">", big_gt, 1);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54831)
+++ ChangeLog	(revision 54832)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Apr 30 13:20:00 2016  Tanaka Akira  <akr@f...>
+
+	* numeric.c (int_fdiv): {Fixnum,Bignum}#fdiv is unified into
+	  Integer.
+
+	* bignum.c (rb_big_fdiv): Don't define Bignum#fdiv.
+
 Sat Apr 30 12:25:43 2016  Tanaka Akira  <akr@f...>
 
 	* numeric.c (rb_int_pow): {Fixnum,Bignum}#** is unified into
Index: numeric.c
===================================================================
--- numeric.c	(revision 54831)
+++ numeric.c	(revision 54832)
@@ -3373,15 +3373,18 @@ rb_int_mul(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3373
 }
 
 /*
- *  Document-method: Fixnum#fdiv
+ *  Document-method: Integer#fdiv
  *  call-seq:
- *     fix.fdiv(numeric)  ->  float
+ *     integer.fdiv(numeric)  ->  float
  *
  *  Returns the floating point result of dividing +fix+ by +numeric+.
  *
  *     654321.fdiv(13731)      #=> 47.6528293642124
  *     654321.fdiv(13731.24)   #=> 47.6519964693647
  *
+ *     -1234567890987654321.fdiv(13731)      #=> -89910996357705.5
+ *     -1234567890987654321.fdiv(13731.24)   #=> -89909424858035.7
+ *
  */
 
 static VALUE
@@ -3402,6 +3405,18 @@ fix_fdiv(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3405
 }
 
 static VALUE
+int_fdiv(VALUE x, VALUE y)
+{
+    if (FIXNUM_P(x)) {
+	return fix_fdiv(x, y);
+    }
+    else if (RB_TYPE_P(x, T_BIGNUM)) {
+	return rb_big_fdiv(x, y);
+    }
+    return Qnil;
+}
+
+static VALUE
 fix_divide(VALUE x, VALUE y, ID op)
 {
     if (FIXNUM_P(y)) {
@@ -4816,7 +4831,7 @@ Init_Numeric(void) https://github.com/ruby/ruby/blob/trunk/numeric.c#L4831
     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_cFixnum, "fdiv", fix_fdiv, 1);
+    rb_define_method(rb_cInteger, "fdiv", int_fdiv, 1);
     rb_define_method(rb_cInteger, "**", rb_int_pow, 1);
 
     rb_define_method(rb_cInteger, "abs", int_abs, 0);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]