From 8733177dd07bf4dca25253af02dfafd3cf629874 Mon Sep 17 00:00:00 2001 From: akr Date: Sat, 30 Apr 2016 10:42:06 +0000 Subject: Define Integer#> instead of Bignum#>. * numeric.c (int_gt): Define Integer#>. * bignum.c (rb_big_gt): Don't define Bignum#>. Renamed from big_gt. * internal.h (rb_big_gt): Declared. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54845 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 9 +++++++++ bignum.c | 13 ++----------- internal.h | 1 + numeric.c | 18 ++++++++++++++++-- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index ff3a3f5733..1ec8485df8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Sat Apr 30 19:41:15 2016 Tanaka Akira + + * numeric.c (int_gt): Define Integer#>. + + * bignum.c (rb_big_gt): Don't define Bignum#>. + Renamed from big_gt. + + * internal.h (rb_big_gt): Declared. + Sat Apr 30 19:24:40 2016 Tanaka Akira * numeric.c (int_ge): Define Integer#>=. diff --git a/bignum.c b/bignum.c index 63cbb72ca9..ea2931b80f 100644 --- a/bignum.c +++ b/bignum.c @@ -5432,16 +5432,8 @@ big_op(VALUE x, VALUE y, enum big_op_t op) return Qundef; } -/* - * call-seq: - * big > real -> true or false - * - * Returns true if the value of big is - * greater than that of real. - */ - -static VALUE -big_gt(VALUE x, VALUE y) +VALUE +rb_big_gt(VALUE x, VALUE y) { return big_op(x, y, big_op_gt); } @@ -6857,7 +6849,6 @@ Init_Bignum(void) rb_define_method(rb_cBignum, "%", rb_big_modulo, 1); rb_define_method(rb_cBignum, "==", rb_big_eq, 1); - rb_define_method(rb_cBignum, ">", big_gt, 1); rb_define_method(rb_cBignum, "===", rb_big_eq, 1); #ifdef USE_GMP diff --git a/internal.h b/internal.h index a72f675026..7793c1ab32 100644 --- a/internal.h +++ b/internal.h @@ -787,6 +787,7 @@ VALUE rb_big_abs(VALUE x); VALUE rb_big_size_m(VALUE big); VALUE rb_big_bit_length(VALUE big); VALUE rb_big_remainder(VALUE x, VALUE y); +VALUE rb_big_gt(VALUE x, VALUE y); VALUE rb_big_ge(VALUE x, VALUE y); VALUE rb_big_lt(VALUE x, VALUE y); VALUE rb_big_le(VALUE x, VALUE y); diff --git a/numeric.c b/numeric.c index 9fe4379552..5c3bc2912f 100644 --- a/numeric.c +++ b/numeric.c @@ -3826,11 +3826,12 @@ int_cmp(VALUE x, VALUE y) } /* + * Document-method: Integer#> * Document-method: Fixnum#> * call-seq: - * fix > real -> true or false + * int > real -> true or false * - * Returns +true+ if the value of +fix+ is greater than that of +real+. + * Returns +true+ if the value of +int+ is greater than that of +real+. */ static VALUE @@ -3851,6 +3852,18 @@ fix_gt(VALUE x, VALUE y) } } +static VALUE +int_gt(VALUE x, VALUE y) +{ + if (FIXNUM_P(x)) { + return fix_gt(x, y); + } + else if (RB_TYPE_P(x, T_BIGNUM)) { + return rb_big_gt(x, y); + } + return Qnil; +} + /* * Document-method: Integer#>= * Document-method: Fixnum#>= @@ -4924,6 +4937,7 @@ Init_Numeric(void) rb_define_method(rb_cInteger, "abs", int_abs, 0); rb_define_method(rb_cInteger, "magnitude", int_abs, 0); + rb_define_method(rb_cInteger, ">", int_gt, 1); rb_define_method(rb_cInteger, ">=", int_ge, 1); rb_define_method(rb_cInteger, "<", int_lt, 1); rb_define_method(rb_cInteger, "<=", int_le, 1); -- cgit v1.2.3