Skip to content

Commit 92e9936

Browse files
committed
fix more issues with sorting for roots
1 parent 534e555 commit 92e9936

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/common.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ function roots(p::AbstractPolynomial{T}) where {T <: Number}
109109
comp = companion(chopped_trimmed)
110110
L = eigvals(rot180(comp))
111111
append!(L, zeros(eltype(L), n_trail))
112-
return sort!(L, rev = true, by = real)
112+
by = eltype(L) <: Complex ? norm : identity
113+
return sort!(L, rev = true, by = by)
113114
end
114115

115116
"""

src/polynomials/ChebyshevT.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ terms of the given variable `x`. `x` can be a character, symbol, or string.
1212
1313
```jldoctest
1414
julia> c = ChebyshevT([1, 0, 3, 4])
15-
ChebyshevT([1, 0, 2, 4])
15+
ChebyshevT([1, 0, 3, 4])
1616
17-
julia> ChebyshevT([1, 2, 3], :s)
17+
julia> ChebyshevT([1, 2, 3, 0], :s)
1818
ChebyshevT([1, 2, 3])
1919
2020
julia> one(ChebyshevT)
21-
ChebyshevT(1.0)
21+
ChebyshevT([1.0])
2222
2323
julia> convert(Polynomial, c)
2424
Polynomial(-2 - 12*x + 6*x^2 + 16*x^3)

test/ChebyshevT.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ end
5858
@test c == ChebyshevT([0, -0.25, 0, 0.25])
5959
@test roots(c) sort(r, rev = true)
6060

61-
r = [-1im, 1im]
61+
r = [1im, -1im]
6262
c = fromroots(ChebyshevT, r)
6363
@test c ChebyshevT([1.5 + 0im, 0 + 0im, 0.5 + 0im])
64-
@test roots(c) sort(r, by = real, rev = true)
64+
@test roots(c) r
6565
end
6666

6767
@testset "Values" begin

0 commit comments

Comments
 (0)