diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-04-26 12:23:05 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-04-26 12:23:05 +0000 |
commit | 6f43f54b18fba8d7b958f2027a4b3e096bf47154 (patch) | |
tree | 97d0dbf23437c1210431c17aeb082dfddcbe67d3 /numeric.c | |
parent | a9d4a29fccf6b2c029ba36ba10389205bcfba589 (diff) | |
download | ruby-6f43f54b18fba8d7b958f2027a4b3e096bf47154.tar.gz |
{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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54782 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r-- | numeric.c | 28 |
1 files changed, 20 insertions, 8 deletions
@@ -3936,13 +3936,6 @@ fix_xor(VALUE x, VALUE y) 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) 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) 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); |