From: Squeak <squeak_at_xirr.com>
Date: Tue, 1 Jun 1999 21:05:32 -0400 (EDT)

Just a silly thing, but gcd is defined on lots of things, for example
floats and rationals. It is also incredibly easy to implement for them,
the answer always being 1.

It exists for complexes as well. The algorithm is the same, but there are
4 answers instead of just two: gcd(3,5i) = 1,i,-1,-i. Just take the answer
and multiply it by i (a unit).

You'd need to add rational support support to your complex code, or just a
mod operator. The algorithm is simply:

 gcd(a,b) = ( if(a%b == 0) return b; return(gcd(b,a%b)) );

with sanity checks for a*b != 0, in which case answer is merely the
non-zero arg. (or 0 if they both are 0).

If it turns out to be incredibly easy to add, I'll send a patch.
Received on Tue Jun 01 1999 - 17:38:29 CDT

This archive was generated by hypermail 2.2.0 : Sun Apr 17 2011 - 21:00:02 CDT