我正在尝试使用bhaskara和delta的公式来计算数字的delta,但是它在消息框中给出了NaN
//Variables declaration
int a = 800, b = 500, c = 350;
double delta, a1, a2;
//Formulas
delta = (b*b) - (4*a*c);
a1 = (-b + Math.Sqrt(delta)) / (2 * a);
a2 = (-b - Math.Sqrt(delta)) / (2 * a);
//Output
MessageBox.Show(a1.ToString());
MessageBox.Show(a2.ToString());
答案 0 :(得分:2)
答案 1 :(得分:1)
正如Broots所说的Math.sqrt
为负数将返回NaN。有一个Complex结构应满足您的需求:
Complex c = Complex.Sqrt(-25); // has a value of approximately 0 + 5i