예제 #1
0
 public static double Square(ComplexNumber c)
 {
     return(c.Real * c.Real + c.Img * c.Img);
 }
예제 #2
0
 public bool Approximates(ComplexNumber c, double eps)
 {
     return(Math.Abs(Real - c.Real) < eps && Math.Abs(Img - c.Img) < eps);
 }
예제 #3
0
 /// <summary>
 /// Absolute value is the distance from the origin to the point on the complex plan represented by this ComplexNumber.
 /// </summary>
 public static double Abs(ComplexNumber c)
 {
     return(c.Img == 0 ? Math.Abs(c.Real) : Math.Sqrt(Square(c)));
 }
예제 #4
0
 public static bool ApproxEqual(ComplexNumber c1, ComplexNumber c2, double eps)
 {
     return((double.IsNaN(c1.Real) && double.IsNaN(c2.Real) || Math.Abs(c1.Real - c2.Real) <= eps) &&
            (double.IsNaN(c1.Img) && double.IsNaN(c2.Img) || Math.Abs(c1.Img - c2.Img) <= eps));
 }