diff options
-rw-r--r-- | complex.c | 9 | ||||
-rw-r--r-- | test/ruby/test_complex.rb | 12 |
2 files changed, 12 insertions, 9 deletions
@@ -843,10 +843,11 @@ f_divide(VALUE self, VALUE other, } if (k_numeric_p(other) && f_real_p(other)) { get_dat1(self); - - return f_complex_new2(CLASS_OF(self), - (*func)(dat->real, other), - (*func)(dat->imag, other)); + return f_complex_new2(CLASS_OF(self), + rb_rational_canonicalize( + (*func)(dat->real, other)), + rb_rational_canonicalize( + (*func)(dat->imag, other))); } return rb_num_coerce_bin(self, other, id); } diff --git a/test/ruby/test_complex.rb b/test/ruby/test_complex.rb index 4aa3eda1d4..80d1dc7e55 100644 --- a/test/ruby/test_complex.rb +++ b/test/ruby/test_complex.rb @@ -427,11 +427,13 @@ class Complex_Test < Test::Unit::TestCase assert_equal(Complex(Rational(3,2),Rational(3)), c / Rational(2,3)) c = Complex(1) - r = c / c - assert_instance_of(Complex, r) - assert_equal(1, r) - assert_predicate(r.real, :integer?) - assert_predicate(r.imag, :integer?) + [ 1, Rational(1), c ].each do |d| + r = c / d + assert_instance_of(Complex, r) + assert_equal(1, r) + assert_predicate(r.real, :integer?) + assert_predicate(r.imag, :integer?) + end end def test_quo |