6
6
gcd(x,y)
7
7
8
8
Greatest common (positive) divisor (or zero if `x` and `y` are both zero).
9
+ The arguments may be integer and rational numbers.
10
+
11
+ !!! compat "Julia 1.4"
12
+ Rational arguments require Julia 1.4 or later.
9
13
10
14
# Examples
11
15
```jldoctest
53
57
lcm(x,y)
54
58
55
59
Least common (non-negative) multiple.
60
+ The arguments may be integer and rational numbers.
61
+
62
+ !!! compat "Julia 1.4"
63
+ Rational arguments require Julia 1.4 or later.
56
64
57
65
# Examples
58
66
```jldoctest
@@ -72,16 +80,16 @@ function lcm(a::T, b::T) where T<:Integer
72
80
end
73
81
end
74
82
75
- gcd (a:: Integer ) = a
76
- lcm (a:: Integer ) = a
77
- gcd (a:: Integer , b:: Integer ) = gcd (promote (a,b)... )
78
- lcm (a:: Integer , b:: Integer ) = lcm (promote (a,b)... )
79
- gcd (a:: Integer , b:: Integer... ) = gcd (a, gcd (b... ))
80
- lcm (a:: Integer , b:: Integer... ) = lcm (a, lcm (b... ))
83
+ gcd (a:: Union{ Integer,Rational} ) = a
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... ))
81
89
82
- lcm (abc:: AbstractArray{<:Integer} ) = reduce (lcm, abc; init= one (eltype (abc)))
90
+ lcm (abc:: AbstractArray{<:Union{ Integer,Rational} } ) = reduce (lcm, abc; init= one (eltype (abc)))
83
91
84
- function gcd (abc:: AbstractArray{<:Integer} )
92
+ function gcd (abc:: AbstractArray{<:Union{ Integer,Rational} } )
85
93
a = zero (eltype (abc))
86
94
for b in abc
87
95
a = gcd (a,b)
@@ -100,6 +108,11 @@ Computes the greatest common (positive) divisor of `x` and `y` and their Bézout
100
108
coefficients, i.e. the integer coefficients `u` and `v` that satisfy
101
109
``ux+vy = d = gcd(x,y)``. ``gcdx(x,y)`` returns ``(d,u,v)``.
102
110
111
+ The arguments may be integer and rational numbers.
112
+
113
+ !!! compat "Julia 1.4"
114
+ Rational arguments require Julia 1.4 or later.
115
+
103
116
# Examples
104
117
```jldoctest
105
118
julia> gcdx(12, 42)
@@ -133,7 +146,7 @@ function gcdx(a::T, b::T) where T<:Integer
133
146
end
134
147
a < 0 ? (- a, - s0, - t0) : (a, s0, t0)
135
148
end
136
- gcdx (a:: Integer , b:: Integer ) = gcdx (promote (a,b)... )
149
+ gcdx (a:: Union{ Integer,Rational} , b:: Union{ Integer,Rational} ) = gcdx (promote (a,b)... )
137
150
138
151
# multiplicative inverse of n mod m, error if none
139
152
0 commit comments