负平方根 [英] Negative square root
本文介绍了负平方根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您如何在C ++中求负数的平方根?
我知道它应该返回实数和复数部分,但得到NaN吗?
如何求实数? >
How do you take the square root of a negative number in C++?
I know it should return a real and a complex part, I get a NaN?
How do I take the real part?
推荐答案
#include <complex>
int main()
{
std::complex<double> two_i = std::sqrt(std::complex<double>(-4));
}
或者只是
std::complex<double> sqrt_minus_x(0, std::sqrt(std::abs(x)));
这篇关于负平方根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文