From 69fbb21c12336810b0864f213c6a401c75967c3f Mon Sep 17 00:00:00 2001 From: akr Date: Tue, 26 Apr 2016 12:09:40 +0000 Subject: {Fixnum,Bignum}#>> is unified into Integer. * numeric.c (rb_int_rshift): {Fixnum,Bignum}#>> is unified into Integer. * bignum.c (rb_big_rshift): Don't define Bignum#>>. * internal.h (rb_big_rshift): Declared. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54781 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- numeric.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'numeric.c') diff --git a/numeric.c b/numeric.c index 4ec8f3e0c3..f80991ae40 100644 --- a/numeric.c +++ b/numeric.c @@ -3968,13 +3968,6 @@ fix_lshift(long val, unsigned long width) return LONG2NUM(val); } -/* - * call-seq: - * fix >> count -> integer - * - * Shifts +fix+ right +count+ positions, or left if +count+ is negative. - */ - static VALUE rb_fix_rshift(VALUE x, VALUE y) { @@ -4001,6 +3994,25 @@ fix_rshift(long val, unsigned long i) return LONG2FIX(val); } +/* + * call-seq: + * int >> count -> integer + * + * Shifts +int+ right +count+ positions, or left if +count+ is negative. + */ + +static VALUE +rb_int_rshift(VALUE x, VALUE y) +{ + if (FIXNUM_P(x)) { + return rb_fix_rshift(x, y); + } + else if (RB_TYPE_P(x, T_BIGNUM)) { + return rb_big_rshift(x, y); + } + return Qnil; +} + /* * call-seq: * fix[n] -> 0, 1 @@ -4682,7 +4694,7 @@ Init_Numeric(void) rb_define_method(rb_cFixnum, "[]", fix_aref, 1); rb_define_method(rb_cFixnum, "<<", rb_fix_lshift, 1); - rb_define_method(rb_cFixnum, ">>", rb_fix_rshift, 1); + rb_define_method(rb_cInteger, ">>", rb_int_rshift, 1); rb_define_method(rb_cInteger, "size", int_size, 0); rb_define_method(rb_cInteger, "bit_length", rb_int_bit_length, 0); -- cgit v1.2.3