public LongDecimal DoublePow(LongDecimal a, LongDecimal k, int accuracy = 50) { LongDecimal s = new LongDecimal("1.0", 0); LongDecimal t = new LongDecimal("1.0", -1); LongDecimal y = new LongDecimal("1.0", 0); LongDecimal fact = new LongDecimal("1.0", 0); LongDecimal pow = a.Minus(a, new LongDecimal("1.0", 0)); int i = 0; while (s.Minus(y, t).e > (-accuracy)) { fact = t.Multip(fact, t.Minus(k, new LongDecimal(Convert.ToString(i) + ".0", 0))); i++; fact = t.Multip(fact, pow); if (i != 1) { fact = t.Divided(fact, new LongDecimal(Convert.ToString(i) + ".0", 0), accuracy); } s = s.Plus(s, fact); t = y; y = fact; if ((t.Reduction(t).m.x == "0") && (t.Reduction(t).e == 0)) { break; } } return(s); }
public LongDecimal IntPow(LongDecimal a, LongInteger k) { LongDecimal b = new LongDecimal("1.0", 1); HashSet <char> hsh = new HashSet <char>(); foreach (char i in "02468") { hsh.Add(i); } while (k.StringComparer(k.x, "0")) { if (hsh.Contains(k.x[k.x.Length - 1])) { k = k.Divided(k, new LongInteger("2")); a = a.Multip(a, a); } else { k = k.Minus(k, new LongInteger("1")); b = b.Multip(b, a); } } return(b); }