############################################################################ # # Name: gcd.icn # # Title: Compute greatest cmmon denominator # # Author: Ralph E. Griswold # # Date: May 11, 1989 # ############################################################################ # # This procedure computes the greatest common denominator of two # integers. If both are zero, it fails. # ############################################################################ procedure gcd(i,j) local r if i = j = 0 then fail if i = 0 then return j if j = 0 then return i i := abs(i) j := abs(j) repeat { r := i % j if r = 0 then return j i := j j := r } end