diff options
| author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-06-19 08:19:14 +0000 |
|---|---|---|
| committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-06-19 08:19:14 +0000 |
| commit | 8f7b86edfce80048b1f3e3db60854f903ad06fc9 (patch) | |
| tree | 6d74c396fc6afd2805fde09b4fbeec0794299597 /numeric.c | |
| parent | 2bf7dd8b3f2f15d726b622f108db840cf4209b98 (diff) | |
| download | ruby-8f7b86edfce80048b1f3e3db60854f903ad06fc9.tar.gz ruby-8f7b86edfce80048b1f3e3db60854f903ad06fc9.tar.xz ruby-8f7b86edfce80048b1f3e3db60854f903ad06fc9.zip | |
* 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/trunk@23742 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
| -rw-r--r-- | numeric.c | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -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); |
