Skip to content

Commit 41e026c

Browse files
authored
Add Base.:+(p::AbstractPolynomial) (#441)
* add Base.:+(p::AbstractPolynomial) * add tests for Base.:+(p::AbstractPolynomial)
1 parent 419d65e commit 41e026c

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/common.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,8 @@ Base.:-(p1::AbstractPolynomial, p2::AbstractPolynomial) = +(p1, -p2)
839839
## +(p::P,c::Number) and +(p::P, q::Q) where {T,S,X,P<:SubtypePolynomial{T,X},Q<:SubtypePolynomial{S,X}}
840840
## though the default for poly+poly isn't terrible
841841

842+
Base.:+(p::AbstractPolynomial) = p
843+
842844
# polynomial + scalar; implicit identification of c with c*one(P)
843845
Base.:+(p::P, c::T) where {T,X, P<:AbstractPolynomial{T,X}} = p + c * one(P)
844846

test/StandardBasis.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ end
161161
@test_throws ArgumentError p*d == P([cᵢ*d for cᵢ [a,b,c]]) # can't fix
162162

163163
# poly add
164+
@test +p == p
164165
@test p + q == P([a+a,b+b,c])
165166
@test p - q == P([a-a,b-b,c])
166167
@test p - p == P([0*a])
@@ -211,6 +212,7 @@ end
211212
@test p*d == P([cᵢ*d for cᵢ [a,b,c]])
212213

213214
# poly add
215+
@test +p == p
214216
@test p + q == P([a+a,b+b,c])
215217
@test p - q == P([a-a,b-b,c])
216218
@test_throws MethodError p - p == P([0*a]) # no zeros to make zero polynomial
@@ -260,6 +262,7 @@ end
260262
@test_throws MethodError p*d == P([cᵢ*d for cᵢ [a,b,c]]) # Ok, no * for T
261263

262264
# poly add
265+
@test +p == p
263266
@test p + q == P([a+a,b+b,c])
264267
@test p - q == P([a-a,b-b,c])
265268
@test_throws MethodError p - p == P([0*a]) # no zero(T) to make zero polynomial
@@ -313,6 +316,7 @@ end
313316
@test p*d == P([cᵢ*d for cᵢ [a,b,c]])
314317

315318
# poly add
319+
@test +p == p
316320
@test p + q == P([a+a,b+b,c])
317321
@test p - p == P([0*a])
318322

0 commit comments

Comments
 (0)