aboutsummaryrefslogtreecommitdiffstats
path: root/numeric.c
diff options
context:
space:
mode:
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/numeric.c b/numeric.c
index 6ff074e04e..8ba7d3fd7e 100644
--- a/numeric.c
+++ b/numeric.c
@@ -937,6 +937,7 @@ flo_cmp(VALUE x, VALUE y)
double a, b;
a = RFLOAT_VALUE(x);
+ if (isnan(a)) return Qnil;
switch (TYPE(y)) {
case T_FIXNUM:
b = (double)FIX2LONG(y);
@@ -955,6 +956,11 @@ 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 (a > 0.0) return INT2FIX(1);
+ return INT2FIX(-1);
+ }
return rb_num_coerce_cmp(x, y, rb_intern("<=>"));
}
return rb_dbl_cmp(a, b);