NScumm.Core.Rational.Gcd C# (CSharp) Method

Gcd() public static method

public static Gcd ( int a, int b ) : int
a int
b int
return int
        public static int Gcd(int a, int b)
        {
            // Note: We check for <= instead of < to avoid spurious compiler
            // warnings if T is an unsigned type, i.e. warnings like "comparison
            // of unsigned expression < 0 is always false".
            if (a <= 0)
                a = -a;
            if (b <= 0)
                b = -b;

            while (a > 0)
            {
                int tmp = a;
                a = b % a;
                b = tmp;
            }

            return b;
        }
    }