Post Reply 
(48G) GCD: Greatest Common Divisor
08-31-2018, 02:06 PM
Post: #5
RE: (48G) GCD: Greatest Common Divisor
(08-31-2018 01:18 PM)Werner Wrote:  Since GCD(x,y) = GCD(y,x) that makes no difference.
And when does it throw an error?

If entered: 0 54 GCD, the code returned gcd of 54, as expected.

If entered: 54 0 GCD, stack = {0 54}

SWAP DUP2, stack = {54 0 54 0}

Inside REPEAT, stack = {0 54 0}

MOD, will do an illegal operation 54 % 0, thus ERROR

BTW, I don't know what MOD will do for 54 % 0, ERROR was my guess.
If the calculator returned x % 0 as x, then ignore my post. All is well ...
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (48G) GCD: Greatest Common Divisor - Albert Chan - 08-31-2018 02:06 PM



User(s) browsing this thread: 1 Guest(s)