Exemplo n.º 1
0
        /// <summary>
        /// Calculate the factorial up to the given number
        /// </summary>
        /// <param name="number">The number</param>
        /// <returns>The factorial</returns>
        public static ReallyBigInt BigFactorial(long number)
        {
            ReallyBigInt product = new ReallyBigInt("1");

            for (long index = 1; index <= number; index++)
            {
                product = product.Multiplication(new ReallyBigInt(index.ToString()));
            }
            return(product);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Raise a ReallyBitInt to a power
        /// </summary>
        /// <param name="exponent"></param>
        /// <returns></returns>
        public ReallyBigInt Power(long exponent)
        {
            ReallyBigInt one    = new ReallyBigInt("1");
            ReallyBigInt result = one;

            for (long index = 1; index <= exponent; index++)
            {
                result = result.Multiplication(this);
            }

            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Raise a ReallyBitInt to a power
        /// </summary>
        /// <param name="exponent"></param>
        /// <returns></returns>
        public ReallyBigInt Power(ReallyBigInt exponent)
        {
            ReallyBigInt one    = new ReallyBigInt("1");
            ReallyBigInt result = one;

            for (ReallyBigInt index = one; index.LessThanOrEqual(exponent); index = index.Addition(one))
            {
                result = result.Multiplication(this);
            }

            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Calculate x to the power y
        /// </summary>
        /// <param name="number">The number</param>
        /// <param name="exponent">The exponent</param>
        /// <returns>The answer</returns>
        public static ReallyBigInt Power(ReallyBigInt number, ReallyBigInt exponent)
        {
            if (exponent.value.Equals("0"))
            {
                return(new ReallyBigInt("1"));
            }
            if (exponent.value.Equals("1"))
            {
                return(number);
            }

            ReallyBigInt result = number;

            for (ReallyBigInt index = new ReallyBigInt("2"); index.LessThanOrEqual(exponent); index = index.Addition(new ReallyBigInt("1")))
            {
                result = result.Multiplication(number);
            }
            return(result);
        }