summaryrefslogtreecommitdiffstats
path: root/numeric.c
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-06-21 10:35:50 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-06-21 10:35:50 +0000
commit6a87598d9e9b0b707729715bdc5e1496af36ff16 (patch)
treee1c7250440bd700fe540ee800fe767493e5b71e7 /numeric.c
parent60e15d2d127a881b0284412f9379e48562f1be48 (diff)
merges r23742 from trunk into ruby_1_9_1.
-- * numeric.c (flo_cmp): should always return nil for NaN. * numeric.c (flo_cmp): handle infinite value specially using infinite? method internally. [ruby-dev:38681] git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_9_1@23803 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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 6f59c98a4..a3cb3be1c 100644
--- a/numeric.c
+++ b/numeric.c
@@ -926,6 +926,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);
@@ -944,6 +945,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);