/// <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> /// 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); }