二进制运算符的参数之一必须是包含类型
本文关键字:包含 类型 运算符 参数 二进制 | 更新日期: 2023-09-27 18:27:02
得到一个错误二进制运算符的参数之一必须是包含类型
看不出中操作员过载的错误所在
公共静态Complex运算符出错+(Complex c1,Complex 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();
}
}
}
这是关于C#中复杂结构的文档,其中有一部分解释了为什么您可能会得到NaN
你正在做除法,所以你可能要除以零,你需要进一步调试你的方程,我建议在C#之外用能给你一个NaN