Skip to content

Commit 91c08b2

Browse files
authored
Merge pull request #99 from aytekinar/97-bugfix
Fix the bug in `+` and `-` between `Poly`s and `Number`s
2 parents ec4224b + af6a78b commit 91c08b2

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/Polynomials.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,12 @@ dot(p1::Poly, p2::Poly) = p1 * p2
252252
+{T<:Number}(c::T, p::Poly) = +(p, c)
253253
function +{S,T<:Number}(p::Poly{S}, c::T)
254254
U = promote_type(S,T)
255-
degree(p) == 0 && return Poly(U[c], p.var)
256255
p2 = U == S ? copy(p) : convert(Poly{U}, p)
257256
p2[0] += c
258257
return p2
259258
end
260259
function -{T<:Number,S}(c::T, p::Poly{S})
261260
U = promote_type(S,T)
262-
degree(p) == 0 && return Poly(U[c], p.var)
263261
p2 = convert(Poly{U}, -p)
264262
p2[0] += c
265263
return p2

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,5 @@ p = Poly([0,one(Float64)])
289289
@test Poly{Complex{Float64}} == typeof(p+1im)
290290
@test Poly{Complex{Float64}} == typeof(1im-p)
291291
@test Poly{Complex{Float64}} == typeof(p*1im)
292+
@test Poly([0.5]) + 2 == Poly([2.5])
293+
@test 2 - Poly([0.5]) == Poly([1.5])

0 commit comments

Comments
 (0)