public static Complex Divide(Complex dividend, Complex divider)
        {
            if (Math.Abs(divider._real) < Eps && Math.Abs(divider._imaginary) < Eps)
            {
                ZeroDivideEventArgs args = new ZeroDivideEventArgs(dividend, divider);
                dividend.OnZeroDivide(args);
                return(Error);
            }
            Complex result = new Complex();

            result._real = (dividend._real * divider._real + dividend._imaginary * divider._imaginary) /
                           (Math.Pow(divider._real, 2) + Math.Pow(divider._imaginary, 2));
            result._imaginary = (divider._real * dividend._imaginary - dividend._real * divider._imaginary) /
                                (Math.Pow(divider._real, 2) + Math.Pow(divider._imaginary, 2));
            return(result);
        }
示例#2
0
 static void ZeroDivide(object sender, ZeroDivideEventArgs e)
 {
     Console.WriteLine($"something in division is not ok.  Blame them: {e._dividend} and {e._divider}");
 }
 protected void OnZeroDivide(ZeroDivideEventArgs e)
 {
     ZeroDivide?.Invoke(this, e);
 }