summaryrefslogtreecommitdiff
path: root/rational.c
diff options
context:
space:
mode:
Diffstat (limited to 'rational.c')
-rw-r--r--rational.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/rational.c b/rational.c
index de676dc473..a75235f65f 100644
--- a/rational.c
+++ b/rational.c
@@ -902,6 +902,10 @@ nurat_coerce(VALUE self, VALUE other)
return rb_assoc_new(other, f_to_f(self));
case T_RATIONAL:
return rb_assoc_new(other, self);
+ case T_COMPLEX:
+ if (k_exact_p(RCOMPLEX(other)->imag) && f_zero_p(RCOMPLEX(other)->imag))
+ return rb_assoc_new(f_rational_new_bang1
+ (CLASS_OF(self), RCOMPLEX(other)->real), self);
}
rb_raise(rb_eTypeError, "%s can't be coerced into %s",