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

ruby-changes:42708

From: akr <ko1@a...>
Date: Tue, 26 Apr 2016 20:26:29 +0900 (JST)
Subject: [ruby-changes:42708] akr:r54782 (trunk): {Fixnum, Bignum}#<< is unified into Integer.

akr	2016-04-26 21:23:05 +0900 (Tue, 26 Apr 2016)

  New Revision: 54782

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

  Log:
    {Fixnum,Bignum}#<< is unified into Integer.
    
    * numeric.c (rb_int_lshift): {Fixnum,Bignum}#<< is unified into
      Integer.
    
    * bignum.c (rb_big_lshift): Don't define Bignum#<<.
    
    * internal.h (rb_big_lshift): Declared.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c
    trunk/numeric.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54781)
+++ ChangeLog	(revision 54782)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Apr 26 21:11:02 2016  Tanaka Akira  <akr@f...>
+
+	* numeric.c (rb_int_lshift): {Fixnum,Bignum}#<< is unified into
+	  Integer.
+
+	* bignum.c (rb_big_lshift): Don't define Bignum#<<.
+
+	* internal.h (rb_big_lshift): Declared.
+
 Tue Apr 26 20:59:40 2016  Tanaka Akira  <akr@f...>
 
 	* numeric.c (rb_int_rshift): {Fixnum,Bignum}#>> is unified into
Index: bignum.c
===================================================================
--- bignum.c	(revision 54781)
+++ bignum.c	(revision 54782)
@@ -7013,7 +7013,6 @@ Init_Bignum(void) https://github.com/ruby/ruby/blob/trunk/bignum.c#L7013
     rb_define_method(rb_cBignum, "|", rb_big_or, 1);
     rb_define_method(rb_cBignum, "^", rb_big_xor, 1);
     rb_define_method(rb_cBignum, "~", rb_big_neg, 0);
-    rb_define_method(rb_cBignum, "<<", rb_big_lshift, 1);
     rb_define_method(rb_cBignum, "[]", rb_big_aref, 1);
 
     rb_define_method(rb_cBignum, "==", rb_big_eq, 1);
Index: numeric.c
===================================================================
--- numeric.c	(revision 54781)
+++ numeric.c	(revision 54782)
@@ -3936,13 +3936,6 @@ fix_xor(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3936
     return rb_funcall(x, '^', 1, y);
 }
 
-/*
- * call-seq:
- *   fix << count  ->  integer
- *
- * Shifts +fix+ left +count+ positions, or right if +count+ is negative.
- */
-
 static VALUE
 rb_fix_lshift(VALUE x, VALUE y)
 {
@@ -3968,6 +3961,25 @@ fix_lshift(long val, unsigned long width https://github.com/ruby/ruby/blob/trunk/numeric.c#L3961
     return LONG2NUM(val);
 }
 
+/*
+ * call-seq:
+ *   fix << count  ->  integer
+ *
+ * Shifts +fix+ left +count+ positions, or right if +count+ is negative.
+ */
+
+static VALUE
+rb_int_lshift(VALUE x, VALUE y)
+{
+    if (FIXNUM_P(x)) {
+	return rb_fix_lshift(x, y);
+    }
+    else if (RB_TYPE_P(x, T_BIGNUM)) {
+	return rb_big_lshift(x, y);
+    }
+    return Qnil;
+}
+
 static VALUE
 rb_fix_rshift(VALUE x, VALUE y)
 {
@@ -4693,7 +4705,7 @@ Init_Numeric(void) https://github.com/ruby/ruby/blob/trunk/numeric.c#L4705
     rb_define_method(rb_cFixnum, "^", fix_xor, 1);
     rb_define_method(rb_cFixnum, "[]", fix_aref, 1);
 
-    rb_define_method(rb_cFixnum, "<<", rb_fix_lshift, 1);
+    rb_define_method(rb_cInteger, "<<", rb_int_lshift, 1);
     rb_define_method(rb_cInteger, ">>", rb_int_rshift, 1);
 
     rb_define_method(rb_cInteger, "size", int_size, 0);

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

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