Skip to content

Commit f2c4a0e

Browse files
authored
add convert method for LaurentPolynomial; close issue #287 (#289)
1 parent eaf31c4 commit f2c4a0e

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/polynomials/LaurentPolynomial.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ function Base.convert(P::Type{<:Polynomial}, q::LaurentPolynomial)
152152
P([q[i] for i in 0:n], q.var)
153153
end
154154

155+
Base.convert(::Type{T}, p::LaurentPolynomial) where {T<:LaurentPolynomial} = T(p.coeffs, p.m[], p.var)
156+
155157
function Base.convert(::Type{P}, q::StandardBasisPolynomial{S}) where {T, P <:LaurentPolynomial{T},S}
156158
d = degree(q)
157159
P([q[i] for i in 0:d], 0, q.var)

test/StandardBasis.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,9 @@ end
436436
p2[3] = 3
437437
@test p1[3] == 3
438438

439+
# issue #287
440+
p = LaurentPolynomial([1], -5)
441+
@test p convert(LaurentPolynomial{Float64}, p)
439442
end
440443

441444
@testset "Roots" begin

0 commit comments

Comments
 (0)