コード例 #1
0
        public Fraction64 Divide(long wholeNumber, long numerator, long denominator)
        {
            if (_numerator == 0 && _wholeNumber == 0)
            {
                return(Fraction64.Zero);
            }

            if (numerator == 0 && wholeNumber == 0)
            {
                throw new DivideByZeroException();
            }

            long w1 = _wholeNumber, n1 = _numerator, d1 = _denominator, w2, n2, d2;

            w2 = FractionUtil.GetInvertedRational64(wholeNumber, numerator, denominator, out n2, out d2);

            if (n2 == 0 && w2 == 0)
            {
                throw new DivideByZeroException();
            }

            w1 = FractionUtil.GetNormalizedRational64(w1 * w2, n1 * n2, d1 * d2, out n1, out d1);
            return(new Fraction64((long)w1, (long)n1, (long)d1));
        }