summaryrefslogtreecommitdiff
path: root/rational.c
diff options
context:
space:
mode:
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))