summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--bignum.c2
-rw-r--r--rational.c17
-rw-r--r--test/ruby/test_bignum.rb1
4 files changed, 26 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index f7f7f8127a..4a3322ff1d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Tue Aug 3 20:30:16 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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 <naruse@ruby-lang.org>
* ext/mkext.rb: remove purelib, fixes a bug in r28440, r28441.
diff --git a/bignum.c b/bignum.c
index c2ceca74d8..1dd43df494 100644
--- a/bignum.c
+++ b/bignum.c
@@ -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