Jump to content

Greatest common divisor: Difference between revisions

Line 2,474:
=={{header|Phix}}==
result is always positive, except for gcd(0,0) which is 0<br>
atom parameters allow greater precision, but any fractional parts are immediately and deliberately discarded.<br>
Actually, it is an autoinclude, reproduced below. The first parameter can be a sequence, in which case the second parameter (if provided) is ignored.
<lang Phix>function gcd(atomobject u, atom v)
atom t
if sequence(u) then
v = u[1] -- (for the typecheck)
t = floor(abs(v))
for i=2 to length(u) do
v = u[i] -- (for the typecheck)
t = gcd(t,v)
end for
return t
end if
u = floor(abs(u))
v = floor(abs(v))
Line 2,504 ⟶ 2,514:
60000000000000000000000)
-- 10000000000000000000
gcd({57,0,-45,-18,90,447}) -- 3
</pre>
 
 
=={{header|PicoLisp}}==
7,820

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.