Talk:Greatest common divisor: Difference between revisions

From Rosetta Code
Content added Content deleted
(→‎errors in programs: add gcd(0,0) case)
m (→‎errors in programs: verifying a special case wording, |0| = 0. -- ~~~~)
Line 3: Line 3:
A few programs would attempt to divide by zero if the 2nd argument is 0 (zero).
A few programs would attempt to divide by zero if the 2nd argument is 0 (zero).
<br> In that special case, the absolute value of the first argument should be returned.
<br> In that special case, the absolute value of the first argument should be returned.

::unless it is 0 --[[User:Walterpachl|Walterpachl]] 12:40, 17 August 2012 (UTC)
::unless it is 0 --[[User:Walterpachl|Walterpachl]] 12:40, 17 August 2012 (UTC)

::: The absolute value of zero ''is'' zero. -- [[User:Gerard Schildberger|Gerard Schildberger]] 15:23, 17 August 2012 (UTC)


<br><br>A number of examples don't show the results if either argument is negative.
<br><br>A number of examples don't show the results if either argument is negative.

Revision as of 15:23, 17 August 2012

errors in programs

A few programs would attempt to divide by zero if the 2nd argument is 0 (zero).
In that special case, the absolute value of the first argument should be returned.

unless it is 0 --Walterpachl 12:40, 17 August 2012 (UTC)
The absolute value of zero is zero. -- Gerard Schildberger 15:23, 17 August 2012 (UTC)



A number of examples don't show the results if either argument is negative.

REXX Version 1

These results seem to be wrong:

the GCD of 14 and 0 and 7 is 14 should be 7
the GCD of 0 and 7 is 0 should be 7
the GCD of 0 and 0 is 0 should be ???

correct:

the GCD of 7 and 0 is 7

--Walterpachl 12:06, 17 August 2012 (UTC)

PL/I

should return a positive integer

and take care of gcd/0,0)

--Walterpachl 12:39, 17 August 2012 (UTC)