Exemple #1
0
        /// <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));
        }