Skip to content

Commit 20f45f0

Browse files
committed
Fix: move is_, as_, isreal & real to src/common.jl
1 parent d5c371c commit 20f45f0

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

src/abstract.jl

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,6 @@ 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)) # Do not export
22-
as_(fn, p::P) where {P<:AbstractPolynomial} = (P)(fn.(coeffs(p)), p.var) # Do not export
23-
24-
"""
25-
isreal(p::AbstractPolynomial)
26-
27-
Determine whether a polynomial is a real polynomial, i.e., having only real numbers as coefficients.
28-
29-
See also: [`real`](@ref)
30-
"""
31-
Base.isreal(p::AbstractPolynomial) = is_(isreal, p)
32-
"""
33-
real(p::AbstractPolynomial)
34-
35-
Construct a real polynomial from the real parts of the coefficients of `p`.
36-
37-
See also: [`isreal`](@ref)
38-
39-
!!! note
40-
This could cause losing terms in `p`. This method is usually called on polynomials like `p = Polynomial([1, 2 + 0im, 3.0, 4.0 + 0.0im])` where you want to chop the imaginary parts of the coefficients of `p`.
41-
"""
42-
Base.real(p::AbstractPolynomial) = as_(real, p)
43-
4420
"""
4521
Polynomials.@register(name)
4622

src/common.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,29 @@ function Base.iszero(p::AbstractPolynomial)
298298
return all(iszero.(coeffs(p))) && p[0] == 0
299299
end
300300

301+
# See discussions in https://github.com/JuliaMath/Polynomials.jl/issues/258
302+
is_(fn, p::AbstractPolynomial) = all(fn, coeffs(p)) # Do not export
303+
as_(fn, p::P) where {P<:AbstractPolynomial} = (P)(fn.(coeffs(p)), p.var) # Do not export
304+
305+
"""
306+
isreal(p::AbstractPolynomial)
307+
308+
Determine whether a polynomial is a real polynomial, i.e., having only real numbers as coefficients.
309+
310+
See also: [`real`](@ref)
311+
"""
312+
Base.isreal(p::AbstractPolynomial) = is_(isreal, p)
313+
"""
314+
real(p::AbstractPolynomial)
315+
316+
Construct a real polynomial from the real parts of the coefficients of `p`.
317+
318+
See also: [`isreal`](@ref)
319+
320+
!!! note
321+
This could cause losing terms in `p`. This method is usually called on polynomials like `p = Polynomial([1, 2 + 0im, 3.0, 4.0 + 0.0im])` where you want to chop the imaginary parts of the coefficients of `p`.
322+
"""
323+
Base.real(p::AbstractPolynomial) = as_(real, p)
301324
"""
302325
coeffs(::AbstractPolynomial)
303326

0 commit comments

Comments
 (0)