Skip to content

Commit ead527c

Browse files
committed
Added kwargs to roots and var kwarg to printpoly
1 parent bdfa5e3 commit ead527c

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/Polynomials.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ julia> roots(poly([1,2,3,4]))
612612
1.0
613613
```
614614
"""
615-
function roots(p::Poly{T}) where {T}
615+
function roots(p::Poly{T}; kwargs...) where {T}
616616
R = promote_type(T, Float64)
617617
length(p) == 0 && return zeros(R, 0)
618618

@@ -634,7 +634,7 @@ function roots(p::Poly{T}) where {T}
634634
an = p[end-num_trailing_zeros]
635635
companion[1,:] = -p[(end-num_trailing_zeros-1):-1:num_leading_zeros] / an
636636

637-
D = eigvals(companion)
637+
D = eigvals(companion; kwargs...)
638638
r = zeros(eltype(D),length(p)-num_trailing_zeros-1)
639639
r[1:n] = D
640640
return r

src/show.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ julia> printpoly(stdout, Poly([-1, 0, 1], :z), offset=-1, descending_powers=true
9090
z - z^-1
9191
```
9292
"""
93-
function printpoly(io::IO, p::Poly{T}, mimetype=MIME"text/plain"(); descending_powers=false, offset::Int=0) where {T}
93+
function printpoly(io::IO, p::Poly{T}, mimetype=MIME"text/plain"(); descending_powers=false, offset::Int=0, var=p.var) where {T}
9494
first = true
9595
printed_anything = false
9696
for i in (descending_powers ? reverse(eachindex(p)) : eachindex(p))
97-
printed = showterm(io, p[i], p.var, i+offset, first, mimetype)
97+
printed = showterm(io, p[i], var, i+offset, first, mimetype)
9898
first &= !printed
9999
printed_anything |= printed
100100
end

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ end
283283
@test printpoly_to_string(Poly([2, 3, 1], :z), descending_powers=true, offset=-2) == "1 + 3*z^-1 + 2*z^-2"
284284
@test printpoly_to_string(Poly([-1, 0, 1], :z), offset=-1, descending_powers=true) == "z - z^-1"
285285

286+
# Override symbol in print Issue: #184
287+
@test printpoly_to_string(Poly([1,2,3], "y"), var=:z) == "1 + 2*z + 3*z^2"
288+
@test printpoly_to_string(Poly([1,2,3], "y"), descending_powers=true, var="z") == "3*z^2 + 2*z + 1"
289+
@test printpoly_to_string(Poly([2, 3, 1], :z), descending_powers=true, offset=-2, var=:y) == "1 + 3*y^-1 + 2*y^-2"
290+
@test printpoly_to_string(Poly([-1, 0, 1], :z), offset=-1, descending_powers=true, var='y') == "y - y^-1"
291+
286292
## want to be able to copy and paste
287293
## check hashing
288294
p = poly([1,2,3])

0 commit comments

Comments
 (0)