Ejemplo n.º 1
0
        private Rational(BigInteger top, BigInteger bottom, bool reduced)
        {
            _top    = top;
            _bottom = bottom;

            if (bottom == 0)
            {
                throw new DivideByZeroException();
            }
            else if (bottom < 0)
            {
                _top    = -_top;
                _bottom = -_bottom;
            }

            if (!reduced)
            {
                BigInteger gcd = BigInteger.GreatestCommonDivisor(_top, _bottom);

                if (gcd != BigInteger.One)
                {
                    _top    /= gcd;
                    _bottom /= gcd;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns the least common multiple (<c>lcm</c>) of two big integers.
        /// </summary>
        /// <param name="a">First Integer: a.</param>
        /// <param name="b">Second Integer: b.</param>
        /// <returns>Least common multiple <c>lcm</c>(a,b)</returns>
        public static BigInteger LeastCommonMultiple(BigInteger a, BigInteger b)
        {
            if (a.IsZero || b.IsZero)
            {
                return(BigInteger.Zero);
            }

            return(BigInteger.Abs((a / BigInteger.GreatestCommonDivisor(a, b)) * b));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Returns the greatest common divisor (<c>gcd</c>) of two big integers.
 /// </summary>
 /// <param name="a">First Integer: a.</param>
 /// <param name="b">Second Integer: b.</param>
 /// <returns>Greatest common divisor <c>gcd</c>(a,b)</returns>
 public static BigInteger GreatestCommonDivisor(BigInteger a, BigInteger b)
 {
     return(BigInteger.GreatestCommonDivisor(a, b));
 }
Ejemplo n.º 4
0
 public static Int Lcm(this Int value1, Int value2)
 {
     return(value1 * value2 / Int.GreatestCommonDivisor(value1, value2));
 }
Ejemplo n.º 5
0
 public BigInt gcd(BigInt x)
 {
     return(FSBigInt.GreatestCommonDivisor(_num, x._num));
 }