Beispiel #1
0
        /// <summary>
        /// Finds the greatest common divisor and reduces the fraction by this amount.
        /// </summary>
        /// <returns>the reduced rational</returns>
        public Rational <T> Reduce()
        {
            T numerator   = this.numerator;
            T denominator = this.denominator;

            Rational <T> .Reduce(ref numerator, ref denominator);

            return(new Rational <T>(numerator, denominator));
        }
Beispiel #2
0
        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="numerator">The numerator of the rational number.</param>
        /// <param name="denominator">The denominator of the rational number.</param>
        /// <param name="reduce">determines if should reduce by greatest common divisor</param>
        /// /// <remarks>reduces by default</remarks>
        public Rational(T numerator, T denominator, bool reduce = true)
        {
            this.numerator   = numerator;
            this.denominator = denominator;

            if (reduce)
            {
                Rational <T> .Reduce(ref this.numerator, ref this.denominator);
            }
        }