aboutsummaryrefslogtreecommitdiffstats
path: root/numeric.c
diff options
context:
space:
mode:
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/numeric.c b/numeric.c
index eb3d4be9ff..81be28cc33 100644
--- a/numeric.c
+++ b/numeric.c
@@ -1016,7 +1016,7 @@ rb_dbl_cmp(double a, double b)
static VALUE
flo_cmp(VALUE x, VALUE y)
{
- double a, b;
+ double a, b, i;
a = RFLOAT_VALUE(x);
if (isnan(a)) return Qnil;
@@ -1038,8 +1038,12 @@ flo_cmp(VALUE x, VALUE y)
break;
default:
- if (isinf(a) && (!rb_respond_to(y, rb_intern("infinite?")) ||
- !RTEST(rb_funcall(y, rb_intern("infinite?"), 0, 0)))) {
+ if (isinf(a) && (i = rb_check_funcall(y, rb_intern("infinite?"), 0, 0)) != Qundef) {
+ if (RTEST(i)) {
+ int j = rb_cmpint(i, x, y);
+ j = (a > 0.0) ? (j > 0 ? 0 : +1) : (j < 0 ? 0 : -1);
+ return INT2FIX(j);
+ }
if (a > 0.0) return INT2FIX(1);
return INT2FIX(-1);
}