summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-03 11:30:19 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-03 11:30:19 +0000
commit292c39098da3d6c9036eabcb9f8a5f7b07c86ab0 (patch)
tree68be083dd5ad5bdbb239e14de19d8b47dd589970
parentb5dc2576cc60930099cd942ffa1de2c2d759471b (diff)
* 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
-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 f7f7f81..4a3322f 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 c2ceca7..1dd43df 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 1d4f1ab..3965144 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 13b5b9d..264c68b 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