From: Morris M. S. <mmm...@gm...> - 2014-03-24 02:01:00
|
Although the suggested code i := (0 < i) | -i j := (0 < j) | -j if j = 0 then if i ~= 0 then return i else runerr(501) if i = 0 then if j ~= 0 then return j else runerr(501) works and is okay from a practical standpoint, it bothers me somewhat from an esthetic standpoint: (1) if i = 0, -i is unnecessarily computed; (2) if i >= 0, i := i is superfluous; (3,4) similarly re. j; (5) in the 4th line, testing j ~= 0 is redundant, since if j = 0 the 3rd line either returns i or calls runerr(501). I would respectifully submit the following as a more elegant equivalent: i := -(0 > i) # i := abs(i) j := -(0 > j) # j := abs(j) if (i | j) = 0 then if i = j then runerr(501) # gcd(0,0) is undefined else return (i + j) # gcd(0,k) = k = gcd(k,0) _______________________________________ On Mon, Mar 17, 2014 at 7:22 PM, Gregg Townsend <gm...@cs...> wrote: > On Mar 14, 2014, at 2:17 PM, Steve Wampler <swa...@no...> wrote: > > > > As implemented in numbers.icn, gcd(i,j) throws a runtime error if > > either i or j is negative, or either either i or j = 0. However, > > gcd is computable for all cases except where both i and j = 0.... > > That's a useful change, and it seems to be consistent with most > definitions of GCD (that is, with anyone who even thinks to discuss the > possibility of negative numbers). > > I've put it on the list for the next version. > > > On Mar 14, 2014, at 2:24 PM, Cheyenne Wills <che...@gm...> > wrote: > > > > Maybe one suggestion, have a global variable that if set will either > have gcd behave the old or new way. That way the behavior can be controlled. > > Hidden state in the library is generally dangerous, not to mention the > added complication, so I'm not going to do this. > > Gregg Townsend > Icon Project > University of Arizona > > > > |