CSJ2K.j2k.util.MathUtil.gcd C# (CSharp) Method

gcd() public static method

Method that calculates the Greatest Common Divisor (GCD) of several positive integer numbers.
public static gcd ( int x ) : int
x int Array containing the numbers. /// ///
return int
        public static int gcd(int[] x)
        {
            if (x.Length < 2)
            {
                throw new System.InvalidOperationException("Do not use this method if there are less than" + " two numbers.");
            }
            int tmp = gcd(x[x.Length - 1], x[x.Length - 2]);
            for (int i = x.Length - 3; i >= 0; i--)
            {
                if (x[i] < 0)
                {
                    throw new System.ArgumentException("Cannot compute the least " + "common multiple of " + "several numbers where " + "one, at least," + "is negative.");
                }
                tmp = gcd(tmp, x[i]);
            }
            return tmp;
        }

Same methods

MathUtil::gcd ( int x1, int x2 ) : int