Skip to content

Conversation

@hyrodium
Copy link
Contributor

This PR adds Base.:+(p::AbstractPolynomial) just like +(x::Number) = x in Base.

Before this PR

julia> using Polynomials

julia> q = Polynomial([1,2,3])
Polynomial(1 + 2*x + 3*x^2)

julia> +q
ERROR: MethodError: no method matching +(::Polynomial{Int64, :x})
Closest candidates are:
  +(::P1, ::P2) where {T, X, P1<:Polynomial{T, X}, S, P2<:Polynomial{S, X}} at ~/.julia/dev/Polynomials/src/polynomials/Polynomial.jl:75
  +(::P, ::S) where {T, X, P<:Polynomial{T, X}, S<:Number} at ~/.julia/dev/Polynomials/src/polynomials/Polynomial.jl:58
  +(::P, ::P) where {T, X, P<:AbstractPolynomial{T, X}} at ~/.julia/dev/Polynomials/src/common.jl:864
  ...
Stacktrace:
 [1] top-level scope
   @ REPL[6]:1

julia> a = 3
3

julia> +a
3

After this PR

julia> using Polynomials

julia> q = Polynomial([1,2,3])
Polynomial(1 + 2*x + 3*x^2)

julia> +q
Polynomial(1 + 2*x + 3*x^2)

julia> a = 3
3

julia> +a
3

@codecov
Copy link

codecov bot commented Aug 12, 2022

Codecov Report

Merging #441 (8d26998) into master (419d65e) will decrease coverage by 0.47%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #441      +/-   ##
==========================================
- Coverage   82.83%   82.35%   -0.48%     
==========================================
  Files          23       23              
  Lines        2890     2891       +1     
==========================================
- Hits         2394     2381      -13     
- Misses        496      510      +14     
Impacted Files Coverage Δ
src/common.jl 90.27% <100.00%> (+0.02%) ⬆️
src/polynomials/ngcd.jl 79.66% <0.00%> (-3.90%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@jverzani
Copy link
Member

Thanks! I didn't even know unary method existed.

@jverzani jverzani merged commit 41e026c into JuliaMath:master Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants