-5

出错二元运算符的参数之一必须是包含类型

看不到运算符重载的错误在哪里

公共静态复杂运算符+错误(复杂 c1,复杂 c2)

namespace testComplex
{
    class Program
    {

        public static Complex operator +(Complex c1, Complex c2)
        {
            return new Complex(c1.Real + c2.Real, c1.Imaginary + c2.Imaginary);
        }

        public static Complex operator /(Complex c1, Complex c2)
        {
            return new Complex(c1.Real / c2.Real, c1.Imaginary / c2.Imaginary);
        }

        public static Complex operator *(Complex c1, Complex c2)
        {
            return new Complex(c1.Real * c2.Real, c1.Imaginary * c2.Imaginary + c1.Real * c2.Imaginary + c2.Real * c1.Imaginary);
        }
        public static Complex operator -(Complex c1, Complex c2)
        {
            return new Complex(c1.Real - c2.Real, c1.Imaginary - c2.Imaginary);
        }

        //public static Complex Sqrt -(Complex c1, Complex c2)
        //{
            //return new Complex(c1.Real - c2.Real, c1.Imaginary - c2.Imaginary);
        //}
        static void Main(string[] args)
        {
            Complex a = new Complex(0.5,0);
            Complex b = new Complex(0.6,0);

            //Complex aa = Math.Exp(-(1 / 4) * a * (b / a + Math.Sqrt(-7 * Math.Pow(b, 2) / Math.Pow(a, 2))) / b + (1 / 4) * b * (a / b + Math.Sqrt(-7 * Math.Pow(a, 2) / Math.Pow(b, 2))) / a);
            //Jesus[i] = aa.Real;

            Complex aa = Complex.Exp(-(1 / 4) * a * (b / a + Complex.Sqrt(-7 * Complex.Pow(b, 2) / Complex.Pow(a, 2))) / b + (1 / 4) * b * (a / b + Complex.Sqrt(-7 * Complex.Pow(a, 2) / Complex.Pow(b, 2))) / a);
            Console.WriteLine(aa.Real);
            Console.WriteLine(aa.Imaginary);
            Console.ReadKey();
        }
    }
}
4

1 回答 1

1

是 C# 中复杂结构的文档,有一部分解释了为什么你可能会得到一个NaN

你正在做除法,所以你可能会被零除,你需要进一步调试你的方程,我建议在 C# 之外检查它,用给你一个NaN的值

于 2013-08-10T02:30:05.333 回答