コード例 #1
0
ファイル: Fraction.cs プロジェクト: Rain0Ash/NetExtender
        /// <summary>
        /// Reduces the fraction (finds the greatest common denominator and divides the
        /// numerator/denominator by it).
        /// </summary>
        public Fraction Reduce()
        {
            Int32 numerator = Numerator;

            if (numerator == Int32.MinValue)
            {
                numerator = Int32.MinValue + 1;
            }

            Int32 denominator = Denominator;

            if (denominator == Int32.MinValue)
            {
                denominator = Int32.MinValue + 1;
            }

            Int32 gcd = numerator.Gcd(denominator);

            return(gcd == 0 ? this : new Fraction(numerator / gcd, denominator / gcd));
        }