示例#1
0
        public Rational(int numerator = 1, int divider = 1, int sign = 1, bool reduce = true)
        {
            if (divider == 0)
            {
                throw new DivideByZeroException();
            }

            var(n, d) = (reduce) ? GCD.ReduceNumber(Math.Abs(numerator), Math.Abs(divider)) : (numerator, divider);

            this.numerator = n;
            this.divider   = d;
            this.sign      = sign;
        }
示例#2
0
文件: GCD.cs 项目: NepeinAV/OOP
        public static (int, int) ReduceNumber(int numerator, int divider)
        {
            int maxDivider = GCD.findGCD(numerator, divider);

            return(numerator / maxDivider, divider / maxDivider);
        }