예제 #1
0
        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));
        }
예제 #2
0
 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;
 }