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; }
public static (int, int) ReduceNumber(int numerator, int divider) { int maxDivider = GCD.findGCD(numerator, divider); return(numerator / maxDivider, divider / maxDivider); }