Anonymous user
Greatest common divisor: Difference between revisions
→{{header|Julia}}
(→Tests: Rust 0.8 printing) |
|||
Line 1,274:
=={{header|Julia}}==
Julia includes a built-in <code>gcd</code> function:
<pre>julia> gcd(4,12)▼
4▼
julia> gcd(6,12)▼
6▼
julia> gcd(7,12)▼
1</pre>▼
The actual implementation of this function in Julia 0.2's standard library is reproduced here:
<lang julia>function gcd{T<:Integer}(a::T, b::T)
neg = a < 0
Line 1,285 ⟶ 1,292:
neg ? -g : g
end</lang>
(For arbitrary-precision integers, Julia calls a different implementation from the GMP library.)
▲<pre>julia> gcd(4,12)
▲4
▲julia> gcd(6,12)
▲6
▲julia> gcd(7,12)
▲1</pre>
=={{header|K}}==
|