Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/polynomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,9 @@ function mapcoefficientsnz(f::Function, p::AbstractPolynomialLike)
polynomial(mapcoefficientsnz.(f, terms(p)), SortedUniqState())
end
mapcoefficientsnz(f::Function, t::AbstractTermLike) = f(coefficient(t)) * monomial(t)

Base.round(t::AbstractTermLike) = round(coefficient(t)) * monomial(t)
function Base.round(p::AbstractPolynomialLike)
# round(0.1) is zero so we cannot use SortedUniqState
polynomial(round.(terms(p)), SortedState())
end
3 changes: 3 additions & 0 deletions test/polynomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
@test polynomial([1 2; 3 4], monovec([y, x^2])) == x^4 + 5x^2*y + 4y^2
@test polynomial([1 2; 3 4], monovec([y, x^2]), Float64) isa AbstractPolynomial{Float64}

@test (@inferred round(2.6x + 1.001x^2)) == 3x + 1x^2
@test (@inferred round(3.1x*y)) == 3x*y

@testset "Graded Lex Order" begin
Mod.@polyvar x y z
p = 3*y^2 + 2*y*x
Expand Down