summaryrefslogtreecommitdiff
path: root/rational.c
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 /rational.c
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
Diffstat (limited to 'rational.c')
-rw-r--r--rational.c17
1 files changed, 17 insertions, 0 deletions
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))