aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--complex.c17
-rw-r--r--internal.h3
-rw-r--r--numeric.c12
-rw-r--r--rational.c6
4 files changed, 25 insertions, 13 deletions
diff --git a/complex.c b/complex.c
index 157201aef3..4737891270 100644
--- a/complex.c
+++ b/complex.c
@@ -97,12 +97,21 @@ f_div(VALUE x, VALUE y)
return rb_funcall(x, '/', 1, y);
}
-inline static VALUE
+inline static int
f_gt_p(VALUE x, VALUE y)
{
- if (FIXNUM_P(x) && FIXNUM_P(y))
- return f_boolcast(FIX2LONG(x) > FIX2LONG(y));
- return rb_funcall(x, '>', 1, y);
+ if (RB_INTEGER_TYPE_P(x)) {
+ if (FIXNUM_P(x) && FIXNUM_P(y))
+ return (SIGNED_VALUE)x > (SIGNED_VALUE)y;
+ return RTEST(rb_int_gt(x, y));
+ }
+ else if (RB_FLOAT_TYPE_P(x))
+ return RTEST(rb_float_gt(x, y));
+ else if (RB_TYPE_P(x, T_RATIONAL)) {
+ int const cmp = rb_cmpint(rb_rational_cmp(x, y), x, y);
+ return cmp > 0;
+ }
+ return RTEST(rb_funcall(x, '>', 1, y));
}
inline static VALUE
diff --git a/internal.h b/internal.h
index 153b9e02e8..ab69abb95f 100644
--- a/internal.h
+++ b/internal.h
@@ -1178,6 +1178,8 @@ VALUE rb_int_round(VALUE num, int ndigits, enum ruby_num_rounding_mode mode);
VALUE rb_int2str(VALUE num, int base);
VALUE rb_dbl_hash(double d);
VALUE rb_fix_plus(VALUE x, VALUE y);
+VALUE rb_int_gt(VALUE x, VALUE y);
+VALUE rb_float_gt(VALUE x, VALUE y);
VALUE rb_int_ge(VALUE x, VALUE y);
enum ruby_num_rounding_mode rb_num_get_rounding_option(VALUE opts);
double rb_int_fdiv_double(VALUE x, VALUE y);
@@ -1385,6 +1387,7 @@ VALUE rb_lcm(VALUE x, VALUE y);
VALUE rb_rational_reciprocal(VALUE x);
VALUE rb_cstr_to_rat(const char *, int);
VALUE rb_rational_abs(VALUE self);
+VALUE rb_rational_cmp(VALUE self, VALUE other);
/* re.c */
VALUE rb_reg_compile(VALUE str, int options, const char *sourcefile, int sourceline);
diff --git a/numeric.c b/numeric.c
index e82f0bd518..38668ec0d9 100644
--- a/numeric.c
+++ b/numeric.c
@@ -1494,8 +1494,8 @@ flo_cmp(VALUE x, VALUE y)
* implementation-dependent value is returned.
*/
-static VALUE
-flo_gt(VALUE x, VALUE y)
+VALUE
+rb_float_gt(VALUE x, VALUE y)
{
double a, b;
@@ -4074,8 +4074,8 @@ fix_gt(VALUE x, VALUE y)
}
}
-static VALUE
-int_gt(VALUE x, VALUE y)
+VALUE
+rb_int_gt(VALUE x, VALUE y)
{
if (FIXNUM_P(x)) {
return fix_gt(x, y);
@@ -5270,7 +5270,7 @@ Init_Numeric(void)
rb_define_method(rb_cInteger, "===", rb_int_equal, 1);
rb_define_method(rb_cInteger, "==", rb_int_equal, 1);
- rb_define_method(rb_cInteger, ">", int_gt, 1);
+ rb_define_method(rb_cInteger, ">", rb_int_gt, 1);
rb_define_method(rb_cInteger, ">=", rb_int_ge, 1);
rb_define_method(rb_cInteger, "<", int_lt, 1);
rb_define_method(rb_cInteger, "<=", int_le, 1);
@@ -5411,7 +5411,7 @@ Init_Numeric(void)
rb_define_method(rb_cFloat, "==", flo_eq, 1);
rb_define_method(rb_cFloat, "===", flo_eq, 1);
rb_define_method(rb_cFloat, "<=>", flo_cmp, 1);
- rb_define_method(rb_cFloat, ">", flo_gt, 1);
+ rb_define_method(rb_cFloat, ">", rb_float_gt, 1);
rb_define_method(rb_cFloat, ">=", flo_ge, 1);
rb_define_method(rb_cFloat, "<", flo_lt, 1);
rb_define_method(rb_cFloat, "<=", flo_le, 1);
diff --git a/rational.c b/rational.c
index f2b83a347a..f7af5ca353 100644
--- a/rational.c
+++ b/rational.c
@@ -1063,8 +1063,8 @@ nurat_expt(VALUE self, VALUE other)
* Rational(1,3) <=> 1 #=> -1
* Rational(1,3) <=> 0.3 #=> 1
*/
-static VALUE
-nurat_cmp(VALUE self, VALUE other)
+VALUE
+rb_rational_cmp(VALUE self, VALUE other)
{
if (RB_INTEGER_TYPE_P(other)) {
{
@@ -2648,7 +2648,7 @@ Init_Rational(void)
rb_define_method(rb_cRational, "fdiv", nurat_fdiv, 1);
rb_define_method(rb_cRational, "**", nurat_expt, 1);
- rb_define_method(rb_cRational, "<=>", nurat_cmp, 1);
+ rb_define_method(rb_cRational, "<=>", rb_rational_cmp, 1);
rb_define_method(rb_cRational, "==", nurat_eqeq_p, 1);
rb_define_method(rb_cRational, "coerce", nurat_coerce, 1);