예제 #1
0
        public static Fractionable MakeProperFraction(Fractionable improper)
        {
            int numeratorPartial = (improper.Numerator % improper.Denominator);

            return(new Fractionable
            {
                Whole = (improper.Whole * improper.Denominator + improper.Numerator) / improper.Denominator,
                Numerator = numeratorPartial / GreatestCommonFactor(numeratorPartial, improper.Denominator),
                Denominator = (improper.Denominator) / GreatestCommonFactor(numeratorPartial, improper.Denominator)
            });
        }
예제 #2
0
        public static Fractionable operator +(Fractionable a, Fractionable b)
        {
            int          LowestCommonDenominator = Fractionable.LowestCommonDenominator(a.Denominator, b.Denominator);
            Fractionable intermediary            = new Fractionable
            {
                Whole     = 0,
                Numerator = a.Whole * LowestCommonDenominator
                            + b.Whole * LowestCommonDenominator
                            + a.Numerator * LowestCommonDenominator / a.Denominator
                            + b.Numerator * LowestCommonDenominator / b.Denominator,
                Denominator = LowestCommonDenominator
            };

            return(MakeProperFraction(intermediary));
        }