示例#1
0
        public Rational Add(Rational val)
        {
            BigInteger num  = Numerator.Multiply(val.Denominator).Add(Denominator.Multiply(val.Numerator));
            BigInteger deno = Denominator.Multiply(val.Denominator);

            return(new Rational(num, deno));
        }         /* Rational.add */
示例#2
0
        public Rational Multiply(Rational val)
        {
            BigInteger num  = Numerator.Multiply(val.Numerator);
            BigInteger deno = Denominator.Multiply(val.Denominator);

            /* Normalization to an coprime format will be done inside
             * the ctor() and is not duplicated here.
             */
            return(new Rational(num, deno));
        }
示例#3
0
        public Rational Divide(Rational val)
        {
            if (val.CompareTo(Zero) == 0)
            {
                throw new DivideByZeroException();
            }

            BigInteger num  = Numerator.Multiply(val.Denominator);
            BigInteger deno = Denominator.Multiply(val.Numerator);

            /* Reduction to a coprime format is done inside the ctor,
             * and not repeated here.
             */
            return(new Rational(num, deno));
        }
示例#4
0
        public Rational Add(int val)
        {
            BigInteger val2 = Numerator.Add(Denominator.Multiply(BigInteger.Parse("" + val)));

            return(new Rational(val2, Denominator));
        }