diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | bignum.c | 2 | ||||
-rw-r--r-- | rational.c | 17 | ||||
-rw-r--r-- | test/ruby/test_bignum.rb | 1 |
4 files changed, 26 insertions, 1 deletions
@@ -1,3 +1,10 @@ +Tue Aug 3 20:30:16 2010 Nobuyoshi Nakada <[email protected]> + + * bignum.c (rb_big_eq): never equal to infinity. + [ruby-core:31603] + + * rational.c (nurat_div): hack for integral float divisor. + Tue Aug 3 14:42:12 2010 NARUSE, Yui <[email protected]> * ext/mkext.rb: remove purelib, fixes a bug in r28440, r28441. @@ -1567,7 +1567,7 @@ rb_big_eq(VALUE x, VALUE y) volatile double a, b; a = RFLOAT_VALUE(y); - if (isnan(a)) return Qfalse; + if (isnan(a) || isinf(a)) return Qfalse; b = rb_big2dbl(x); return (a == b)?Qtrue:Qfalse; } 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)) diff --git a/test/ruby/test_bignum.rb b/test/ruby/test_bignum.rb index 13b5b9dbe0..264c68bcf7 100644 --- a/test/ruby/test_bignum.rb +++ b/test/ruby/test_bignum.rb @@ -193,6 +193,7 @@ class TestBignum < Test::Unit::TestCase assert(T31P != 1) assert(T31P == 2147483647.0) assert(T31P != "foo") + assert(2**77889 != (1.0/0.0), '[ruby-core:31603]') end def test_eql |