public static DecimalComplex Power(DecimalComplex v, DecimalComplex e) { if (e == 0) { return(1); } if (v == 0) { return(0); } if (e.Imaginary == 0) { if (v.Imaginary == 0 && v.Real > 0) { return(pwr(v.Real, e.Real)); } decimal a = v.Real, b = v.Imaginary, m = v.Magnitude; var f = frac(e.Real); DecimalComplex r = 1; for (int i = 0; i < f.Item1; ++i) { r *= v; } int d = f.Item2; while (d % 2 == 0) { d /= 2; r = Sqrt(r); } return(FromPolar(root(r.Magnitude, d), r.Phase / d)); } return(Power(v, e.Real) * (cos(e.Imaginary, 100) + new DecimalComplex(0, 1) * sin(e.Imaginary, 100))); }
public static DecimalComplex Sqrt(DecimalComplex v) { if (v.Imaginary == 0) { if (v.Real > 0) { return(root(v.Real, 2)); } if (v.Real < 0) { return(new DecimalComplex(0, root(-v.Real, 2))); } return(0); } bool invert = v.Imaginary < 0; decimal m = v.Magnitude; decimal q = root(m, 2); v /= q; v.Real += (q - v.Real) / 2; v.Imaginary = v.Imaginary / 2; v *= m / v.Magnitude; if (invert) { v *= -1; } return(v); }