/// <summary> /// Return the sum of a series of really big numbers /// </summary> /// <param name="numbers">the numbers</param> /// <returns>the sum</returns> public static ReallyBigInt SeriesSum(List <ReallyBigInt> numbers) { ReallyBigInt result = new ReallyBigInt("0"); foreach (ReallyBigInt number in numbers) { result = result.Addition(number); } return(result); }
/// <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); }
/// <summary> /// Multiply two REallyBigInts /// </summary> /// <param name="number">A number</param> /// <returns>The product</returns> public ReallyBigInt Multiplication(ReallyBigInt number) { ReallyBigInt product = new ReallyBigInt("0"); for (int index = 0; index < number.value.Length; index++) { int digit = int.Parse(number.value.Substring(number.value.Length - index - 1, 1)); ReallyBigInt workNumber = new ReallyBigInt("0"); for (int loop = 0; loop < digit; loop++) { workNumber = workNumber.Addition(this); } workNumber.value = workNumber.value + Zeros(index); product = product.Addition(workNumber); } return(product); }
/// <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); }