mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
complex.c (f_divide): canonicalize a quotient
Cannonicalize resultant real and imaginary parts when complex number divided by non-complex number. [Fix GH-2065] [Bug #15505] [ruby-core:90891] From: Joe Peric <peric.joe@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66744 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
72ad092960
commit
a288ff502e
2 changed files with 12 additions and 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));
|
||||
rb_rational_canonicalize(
|
||||
(*func)(dat->real, other)),
|
||||
rb_rational_canonicalize(
|
||||
(*func)(dat->imag, other)));
|
||||
}
|
||||
return rb_num_coerce_bin(self, other, id);
|
||||
}
|
||||
|
|
|
@ -427,12 +427,14 @@ class Complex_Test < Test::Unit::TestCase
|
|||
assert_equal(Complex(Rational(3,2),Rational(3)), c / Rational(2,3))
|
||||
|
||||
c = Complex(1)
|
||||
r = c / c
|
||||
[ 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
|
||||
c = Complex(1,2)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue