Beispiel #1
0
        public BigComplex Sqrt(MathContext mc)
        {
            BigDecimal half = new BigDecimal(2);

            /* compute l=sqrt(re^2+im^2), then u=sqrt((l+re)/2)
             * and v= +- sqrt((l-re)/2 as the new real and imaginary parts.
             */
            BigDecimal l = Abs(mc);

            if (l.CompareTo(BigDecimal.Zero) == 0)
            {
                return(new BigComplex(BigMath.ScalePrecision(BigDecimal.Zero, mc),
                                      BigMath.ScalePrecision(BigDecimal.Zero, mc)));
            }
            BigDecimal u = BigMath.Sqrt(l.Add(Real).Divide(half, mc), mc);
            BigDecimal v = BigMath.Sqrt(l.Subtract(Real).Divide(half, mc), mc);

            if (Imaginary.CompareTo(BigDecimal.Zero) >= 0)
            {
                return(new BigComplex(u, v));
            }
            else
            {
                return(new BigComplex(u, v.Negate()));
            }
        }
Beispiel #2
0
 public BigDecimal Abs(MathContext mc)
 {
     return(BigMath.Sqrt(Norm(), mc));
 }