|
82 | 82 |
|
83 | 83 | gcd(a::Union{Integer,Rational}) = a
|
84 | 84 | lcm(a::Union{Integer,Rational}) = a
|
85 |
| -gcd(a::Union{Integer,Rational}, b::Union{Integer,Rational}) = gcd(promote(a,b)...) |
86 |
| -lcm(a::Union{Integer,Rational}, b::Union{Integer,Rational}) = lcm(promote(a,b)...) |
87 |
| -gcd(a::Union{Integer,Rational}, b::Union{Integer,Rational}...) = gcd(a, gcd(b...)) |
88 |
| -lcm(a::Union{Integer,Rational}, b::Union{Integer,Rational}...) = lcm(a, lcm(b...)) |
| 85 | +gcd(a::Real, b::Real) = gcd(promote(a,b)...) |
| 86 | +lcm(a::Real, b::Real) = lcm(promote(a,b)...) |
| 87 | +gcd(a::Real, b::Real, c::Real...) = gcd(a, gcd(b, c...)) |
| 88 | +lcm(a::Real, b::Real, c::Real...) = lcm(a, lcm(b, c...)) |
| 89 | +gcd(a::T, b::T) where T<:Real = throw(MethodError(gcd, (a,b))) |
| 90 | +lcm(a::T, b::T) where T<:Real = throw(MethodError(lcm, (a,b))) |
89 | 91 |
|
90 |
| -gcd(abc::AbstractArray{<:Union{Integer,Rational}}) = reduce(gcd, abc; init=zero(eltype(abc))) |
91 |
| -lcm(abc::AbstractArray{<:Union{Integer,Rational}}) = reduce(lcm, abc; init=one(eltype(abc))) |
| 92 | +gcd(abc::AbstractArray{<:Real}) = reduce(gcd, abc; init=zero(eltype(abc))) |
| 93 | +lcm(abc::AbstractArray{<:Real}) = reduce(lcm, abc; init=one(eltype(abc))) |
92 | 94 |
|
93 | 95 | function gcd(abc::AbstractArray{<:Integer})
|
94 | 96 | a = zero(eltype(abc))
|
@@ -147,7 +149,8 @@ function gcdx(a::T, b::T) where T<:Integer
|
147 | 149 | end
|
148 | 150 | a < 0 ? (-a, -s0, -t0) : (a, s0, t0)
|
149 | 151 | end
|
150 |
| -gcdx(a::Union{Integer,Rational}, b::Union{Integer,Rational}) = gcdx(promote(a,b)...) |
| 152 | +gcdx(a::Real, b::Real) = gcdx(promote(a,b)...) |
| 153 | +gcdx(a::T, b::T) where T<:Real = throw(MethodError(gcdx, (a,b))) |
151 | 154 |
|
152 | 155 | # multiplicative inverse of n mod m, error if none
|
153 | 156 |
|
|
0 commit comments