Skip to content

Commit 29e2291

Browse files
feat: support complex coefficient GCD
1 parent d16100a commit 29e2291

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/gcd.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,16 @@ end
7979
_coefficient_gcd(α, β) = gcd(α, β)
8080
_coefficient_gcd::AbstractFloat, β) = one(Base.promote_typeof(α, β))
8181
_coefficient_gcd(α, β::AbstractFloat) = one(Base.promote_typeof(α, β))
82+
_coefficient_gcd::Complex, β) = one(Base.promote_typeof(α, β))
83+
_coefficient_gcd(α, β::Complex) = one(Base.promote_typeof(α, β))
84+
_coefficient_gcd::Complex, β::AbstractFloat) = one(Base.promote_typeof(α, β))
85+
_coefficient_gcd::AbstractFloat, β::Complex) = one(Base.promote_typeof(α, β))
8286
function _coefficient_gcd::AbstractFloat, β::AbstractFloat)
8387
return one(Base.promote_typeof(α, β))
8488
end
89+
function _coefficient_gcd::Complex, β::Complex)
90+
return one(Base.promote_typeof(α, β))
91+
end
8592

8693
function Base.lcm(
8794
p::_APL,

test/commutative/gcd.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,12 @@ end
298298
g = @inferred gcd(p1, p2)
299299
@test isone(g)
300300
end
301+
302+
@testset "Complex coefficient GCD" begin
303+
Mod.@polyvar p q
304+
p1 = MP.polynomial(p^2 + q^2, ComplexF64)
305+
p2 = MP.polynomial(p * q, ComplexF64)
306+
g = @inferred gcd(p1, p2)
307+
@test isone(g)
308+
end
301309
end

0 commit comments

Comments
 (0)