Skip to content

Commit bb11e90

Browse files
authored
Implement div with Number (#180)
* Implement div with Number * Exclude tests for old Julia version
1 parent 5cde13f commit bb11e90

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

src/division.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
export divides
22

3+
Base.round(t::AbstractTermLike; args...) = term(round(coefficient(t); args...), monomial(t))
4+
function Base.round(p::APL; args...)
5+
# round(0.1) is zero so we cannot use SortedUniqState
6+
polynomial!(round.(terms(p); args...), SortedState())
7+
end
8+
9+
Base.div(t::AbstractTermLike, α::Number, args...) = term(div(coefficient(t), α, args...), monomial(t))
10+
function Base.div(p::APL, α::Number, args...)
11+
polynomial!(div.(terms(p), α, args...), SortedState())
12+
end
13+
314
"""
415
divides(t1::AbstractTermLike, t2::AbstractTermLike)
516

src/polynomial.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,12 +403,6 @@ function mapcoefficientsnz(f::Function, p::AbstractPolynomialLike)
403403
end
404404
mapcoefficientsnz(f::Function, t::AbstractTermLike) = term(f(coefficient(t)), monomial(t))
405405

406-
Base.round(t::AbstractTermLike; args...) = term(round(coefficient(t); args...), monomial(t))
407-
function Base.round(p::AbstractPolynomialLike; args...)
408-
# round(0.1) is zero so we cannot use SortedUniqState
409-
polynomial!(round.(terms(p); args...), SortedState())
410-
end
411-
412406
"""
413407
deg_num_leading_terms(p::AbstractPolynomialLike, var)
414408

test/division.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ using Combinatorics
44
using MultivariatePolynomials
55
const MP = MultivariatePolynomials
66

7+
function div_number_test()
8+
Mod.@polyvar x
9+
@test div(2x, 2) == x
10+
@test div(6x + 9x^2, 3) == 2x + 3x^2
11+
@test div(6x + 9x^2, 4) == x + 2x^2
12+
if VERSION >= v"1.6"
13+
@test div(10x^3, 4, RoundUp) == 3x^3
14+
@test div(6x + 9x^2, 4, RoundUp) == 2x + 3x^2
15+
end
16+
end
17+
718
function gcd_lcm_test()
819
Mod.@polyvar x y z
920
@test gcd(x*y, y) == y
@@ -278,6 +289,9 @@ function extracted_variable_test()
278289
end
279290

280291
@testset "Division" begin
292+
@testset "div by number" begin
293+
div_number_test()
294+
end
281295
@testset "GCD and LCM" begin
282296
gcd_lcm_test()
283297
end

0 commit comments

Comments
 (0)