Skip to content

Commit a3e840e

Browse files
authored
Merge pull request #63 from JuliaAlgebra/round
Add Base.round
2 parents d3836b5 + 7a9bafc commit a3e840e

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/polynomial.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,3 +367,9 @@ function mapcoefficientsnz(f::Function, p::AbstractPolynomialLike)
367367
polynomial(mapcoefficientsnz.(f, terms(p)), SortedUniqState())
368368
end
369369
mapcoefficientsnz(f::Function, t::AbstractTermLike) = f(coefficient(t)) * monomial(t)
370+
371+
Base.round(t::AbstractTermLike) = round(coefficient(t)) * monomial(t)
372+
function Base.round(p::AbstractPolynomialLike)
373+
# round(0.1) is zero so we cannot use SortedUniqState
374+
polynomial(round.(terms(p)), SortedState())
375+
end

test/polynomial.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@
115115
@test polynomial([1 2; 3 4], monovec([y, x^2])) == x^4 + 5x^2*y + 4y^2
116116
@test polynomial([1 2; 3 4], monovec([y, x^2]), Float64) isa AbstractPolynomial{Float64}
117117

118+
@test (@inferred round(2.6x + 1.001x^2)) == 3x + 1x^2
119+
@test (@inferred round(3.1x*y)) == 3x*y
120+
118121
@testset "Graded Lex Order" begin
119122
Mod.@polyvar x y z
120123
p = 3*y^2 + 2*y*x

0 commit comments

Comments
 (0)