diff --git a/src/utils.jl b/src/utils.jl index f86ed12c3..8b427d0c7 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -305,6 +305,11 @@ julia> Symbolics.coeff(x^2 + y, x^2) """ function coeff(p, sym=nothing) p, sym = value(p), value(sym) + + if isequal(sym, 1) + sym = nothing + end + if issym(p) || isterm(p) sym === nothing ? 0 : Int(isequal(p, sym)) elseif ispow(p) diff --git a/test/coeff.jl b/test/coeff.jl index 44b874646..1bb74854d 100644 --- a/test/coeff.jl +++ b/test/coeff.jl @@ -39,3 +39,9 @@ e = x*y^2 + 2x + y^3*x^3 @test isequal(coeff(expand(((x + 1)^4 + x)^3), x^2), 93) @test isequal(coeff(simplify((x^2 - 1) / (x - 1)), x), 1) @test isequal(coeff(expand((x^(1//2) + y^0.5)^2), x), 1) + + +# issue #1098 +@test isequal(coeff(x^2 + 1, x^0), 1) +@test isequal(coeff(e, x^0), 0) +@test isequal(coeff(a*x + 3, x^0), 3)