gcd
gcd(x,y)
Greatest common (positive) divisor (or zero if x
and y
are both zero).
Examples
julia> gcd(10, 15)
5
julia> gcd(21, 14)
7
julia> gcd(0, 10)
10
julia> gcd(0, 0)
0
julia> gcd(12, -18)
6
julia> gcd(20, 0)
20
julia> gcd(0, -12)
12
Common mistake example:
julia> gcd(3.5, 5)
ERROR: MethodError: no method matching gcd(::Float64, ::Int64)
In this example, gcd
is called with a floating-point number (Float64
) and an integer (Int64
). The gcd
function only works with integer arguments, so make sure to pass integers to the function for correct results.
See Also
abs2, beta, binomial, ceil, cell, cross, ctranspose, ctranspose!, cummin, cumprod, cumprod!, cumsum, cumsum!, cumsum_kbn, div, divrem, eigfact, eigfact!, eigmin, eps, erf, erfc, erfcinv, erfcx, erfi, erfinv, exp, exp10, exp2, expm1, exponent, factor, factorial, factorize, floor, gcd, invmod, log, log10, log1p, log2, logspace, max, min, mod, mod1, modf, next, nextpow, nextprod, num, primes, primesmask, prod, realmin, sqrt, sum!, sumabs, sumabs!, sumabs2, sumabs2!,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.