aboutsummaryrefslogtreecommitdiffstats
path: root/rational.c
diff options
context:
space:
mode:
Diffstat (limited to 'rational.c')
-rw-r--r--rational.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/rational.c b/rational.c
index 69a0bf6ab6..3fcf82bce5 100644
--- a/rational.c
+++ b/rational.c
@@ -805,6 +805,16 @@ f_muldiv(VALUE self, VALUE anum, VALUE aden, VALUE bnum, VALUE bden, int k)
VALUE num, den;
assert(RB_TYPE_P(self, T_RATIONAL));
+
+ /* Integer#** can return Rational with Float right now */
+ if (RB_FLOAT_TYPE_P(anum) || RB_FLOAT_TYPE_P(aden) ||
+ RB_FLOAT_TYPE_P(bnum) || RB_FLOAT_TYPE_P(bden)) {
+ double an = NUM2DBL(anum), ad = NUM2DBL(aden);
+ double bn = NUM2DBL(bnum), bd = NUM2DBL(bden);
+ double x = (an * bn) / (ad * bd);
+ return DBL2NUM(x);
+ }
+
assert(RB_INTEGER_TYPE_P(anum));
assert(RB_INTEGER_TYPE_P(aden));
assert(RB_INTEGER_TYPE_P(bnum));