Mercurial > octave
changeset 26857:a018fca707ca stable
poly.m: fix the fix for input of complex conjugate pairs (bug #53897).
* poly.m: Calculate positive imaginary parts, and negative imaginary parts
separately. When comparing for complex conjugation, first check that the
positive and negative parts match in number and location, before checking that
they are equal in magnitude. Add BIST test for bug #53897.
author | Marco Caliari <marco.caliari@univr.it> |
---|---|
date | Wed, 06 Mar 2019 15:36:18 +0100 |
parents | b0f359a5ad35 |
children | b4a9888bb3c9 |
files | scripts/polynomial/poly.m |
diffstat | 1 files changed, 12 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/polynomial/poly.m Tue Mar 05 17:53:30 2019 -0800 +++ b/scripts/polynomial/poly.m Wed Mar 06 15:36:18 2019 +0100 @@ -81,9 +81,13 @@ if (isreal (x)) y = real (y); else - tmp = sort (v(imag (v) > 0)) == sort (conj (v(imag (v) < 0))); - if (! isempty (tmp) && all (tmp)) - y = real (y); + pos_imag = sort (v(imag (v) > 0)); + neg_imag = sort (conj (v(imag (v) < 0))); + if (size_equal (pos_imag, neg_imag)) + is_equal = (pos_imag == neg_imag); + if (! isempty (is_equal) && all (is_equal)) + y = real (y); + endif endif endif @@ -100,6 +104,11 @@ %! y = poly (x); %! assert (isreal (y), true); +%!test <53897> +%! x = [1 + 1i, 1 + 2i, 3, 4]; +%! y = poly (x); +%! assert (y, [1 + 0i, -9 - 3i, 25 + 24i, -17 - 57i, -12 + 36i]); + %!error poly () %!error poly (1,2) %!error poly ([1, 2, 3; 4, 5, 6])