From 292c39098da3d6c9036eabcb9f8a5f7b07c86ab0 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 3 Aug 2010 11:30:19 +0000 Subject: * bignum.c (rb_big_eq): never equal to infinity. [ruby-core:31603] * rational.c (nurat_div): hack for integral float divisor. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28844 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- rational.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'rational.c') diff --git a/rational.c b/rational.c index 1d4f1abbd5..3965144b61 100644 --- a/rational.c +++ b/rational.c @@ -869,6 +869,23 @@ nurat_div(VALUE self, VALUE other) other, ONE, '/'); } case T_FLOAT: + { + double x = RFLOAT_VALUE(other), den; + get_dat1(self); + + if (isnan(x)) return DBL2NUM(NAN); + if (isinf(x)) { + if (RTEST(f_negative_p(dat->num)) == (x < 0)) { + return DBL2NUM(INFINITY); + } + else { + return DBL2NUM(-INFINITY); + } + } + if (modf(x, &den) == 0.0) { + return rb_rational_raw2(dat->num, f_mul(rb_dbl2big(den), dat->den)); + } + } return rb_funcall(f_to_f(self), '/', 1, other); case T_RATIONAL: if (f_zero_p(other)) -- cgit v1.2.3