diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-07-24 20:37:31 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-07-24 20:37:31 +0000 |
commit | 7bfa1146e298acb72d9ee0301fcf37acb4699197 (patch) | |
tree | 549d1e9e4d0f59f01716cb30b139e6b283130d2d /numeric.c | |
parent | 8d3bb806b0fd301d5180a211dfe5880fd2ee2506 (diff) | |
download | ruby-7bfa1146e298acb72d9ee0301fcf37acb4699197.tar.gz |
* numeric.c (flo_cmp): honor the result of infinite? method of the
other. [ruby-core:31470]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28751 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r-- | numeric.c | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -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); } |