summaryrefslogtreecommitdiffstats
path: root/rational.c
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-06-17 14:49:10 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-06-17 14:49:10 +0000
commitea2c82e774b796c6aeda1d1a6b16f5168236e404 (patch)
treed01b332bd6df8828734fe78a081ca1ed3cf307c0 /rational.c
parent210af9bf295d0f8e1b96737b5cb69c4dda2e2afb (diff)
downloadruby-ea2c82e774b796c6aeda1d1a6b16f5168236e404.tar.gz
ruby-ea2c82e774b796c6aeda1d1a6b16f5168236e404.tar.xz
ruby-ea2c82e774b796c6aeda1d1a6b16f5168236e404.zip
* rational.c (nurat_coerce): accepts Complex when the imag is
exact zero. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@23727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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 de676dc47..a75235f65 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",