出错了二元运算符的一个参数必须是包含类型
看不到运算符重载的错误
公共静态复杂运算符的错误 + (复杂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();
}
}
}
答案 0 :(得分:1)
Here是关于C#中复杂结构的文档,有一部分解释了为什么你可能会得到 NaN
你正在划分,所以你可能会除以零,你需要进一步调试你的等式,我建议你在C#之外检查它,并给出一个 NaN