Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove gcd and gcdx for Rational{<:Integer} #1409

Merged
merged 1 commit into from
Aug 24, 2023
Merged
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
36 changes: 0 additions & 36 deletions src/julia/Rational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,42 +126,6 @@ function divides(a::T, b::T) where T <: Rational
end
end

###############################################################################
#
# GCD
#
###############################################################################

function gcd(p::Rational{T}, q::Rational{T}) where T <: Integer
a = p.num*q.den
b = p.den*q.num
n = gcd(a, b)
d = p.den*q.den
if d != 1 && n != 0
g = gcd(n, d)
n = divexact(n, g)
d = divexact(d, g)
end
if n == 0
return Rational{T}(n, T(1))
else
return Rational{T}(n, d)
end
end

function gcdx(p::Rational{T}, q::Rational{T}) where {T <: Integer}
g = gcd(p, q)
if !iszero(p)
return (g, g//p, zero(q))
elseif !iszero(q)
return (g, zero(p), g//q)
else
@assert iszero(g)
return (g, zero(p), zero(p))
end
end


###############################################################################
#
# Square root
Expand Down
Loading