public LongDecimal Plus(LongDecimal a, LongDecimal b) { a.Adduction(ref a, ref b); LongDecimal c = new LongDecimal("1.0", a.e); c.e = a.e; if (a.z && b.z) { c.m = c.m.Plus(a.m, b.m); } if (!(a.z || b.z)) { c.m = c.m.Plus(a.m, b.m); c.z = false; } if (!a.z && b.z) { c = c.Minus(b, a); } if (a.z && !b.z) { c = c.Minus(a, b); } a = Reduction(a); b = Reduction(b); c = c.Reduction(c); return(c); }
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); }