Skip to content

Commit 410ccb9

Browse files
committed
Add is_, as_ & extend Base.isreal & Base.real
for `AbstractPolynomial`s
1 parent 930b116 commit 410ccb9

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/abstract.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ abstract type AbstractPolynomial{T} end
1717
# works for most cases
1818
(P::Type{<:AbstractPolynomial}) = constructorof(P)
1919

20+
# See discussions in https://github.com/JuliaMath/Polynomials.jl/issues/258
21+
is_(fn, p::AbstractPolynomial) = all(fn, coeffs(p))
22+
as_(fn, p::P) where {P<:AbstractPolynomial} = (P)(fn.(coeffs(p)), p.var)
23+
24+
Base.isreal(p::AbstractPolynomial) = is_(isreal, p)
25+
Base.real(p::P) where {P<:AbstractPolynomial} = as_(real, p)
26+
2027
"""
2128
Polynomials.@register(name)
2229

0 commit comments

Comments
 (0)