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 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 Divided(LongDecimal a, LongDecimal b, int p = 5) { //Console.WriteLine(); //Console.WriteLine($"{b.m.x} {b.e}"); LongDecimal c = new LongDecimal("1.0", 0); c.z = true; if (a.z != b.z) { c.z = false; } while (a.m.x.Length / b.m.x.Length < (p)) { a.m.x += "0"; a.e--; } c.e = a.e - b.e; Console.WriteLine($"{a.m.x} {a.e} {b.m.x} {b.e}"); c.m = c.m.Divided(a.m, b.m); //Console.WriteLine($"{c.m.x} {c.e}"); c = c.Reduction(c); //a = Reduction(a); //b = Reduction(b); return(c); }
public LongDecimal Multip(LongDecimal a, LongDecimal b) { LongDecimal c = new LongDecimal("1.0", 0); c.m = c.m.ComplexMultiplied(a.m, b.m); c.z = true; if (a.z != b.z) { c.z = false; } c.e = a.e + b.e; c = c.Reduction(c); return(c); }