Skip to content

Commit

Permalink
Remove gcd and gcdx for Rational{<:Integer} (#1409)
Browse files Browse the repository at this point in the history
These are already provided by Julia
  • Loading branch information
fingolfin authored Aug 24, 2023
1 parent e9bc685 commit ca3a1e6
Showing 1 changed file with 0 additions and 36 deletions.
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

0 comments on commit ca3a1e6

Please sign in to comment.