Greatest common divisor: Difference between revisions
Content added Content deleted
Line 2,474: | Line 2,474: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
result is always positive, except for gcd(0,0) which is 0<br> |
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. |
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( |
<lang Phix>function gcd(object u, atom v) |
||
atom t |
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)) |
u = floor(abs(u)) |
||
v = floor(abs(v)) |
v = floor(abs(v)) |
||
Line 2,504: | Line 2,514: | ||
60000000000000000000000) |
60000000000000000000000) |
||
-- 10000000000000000000 |
-- 10000000000000000000 |
||
gcd({57,0,-45,-18,90,447}) -- 3 |
|||
</pre> |
</pre> |
||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |