public static Rational FromBignums(BigNum num, BigNum den) { Contract.Assert(!den.IsZero); if (num == BigNum.ZERO) { return(ZERO); } if (den.Signum < 0) { den = -den; num = -num; } if (den == BigNum.ONE) { return(new Rational(num, den)); } var gcd = num.Gcd(den); if (gcd == BigNum.ONE) { return(new Rational(num, den)); } return(new Rational(num / gcd, den / gcd)); }
private Rational(BigNum num, BigNum den) { Contract.Assert(den.Signum > 0); Contract.Assert(num == BigNum.ZERO || num.Gcd(den) == BigNum.ONE); numerator = num; denominator = den; }