为什么我会收到这些错误? (我有一个clang/g++
编译器。)为什么`ccos`,`csqrt`,`cpow`无法识别?
error: use of undeclared identifier 'ccos'
error: use of undeclared identifier 'csqrt'; did you mean 'sqrt'?
error: use of undeclared identifier 'cpow'; did you mean 'pow'?
等等。我已经宣布我的功能为:
#include <complex>
double ghmc1AccNormalised(double ph, double r, double t, double th){
complex<double> numerator;
complex<double> denominator;
double E = exp(1);
numerator=-(cpow(E,t*((-2*r + r*ccos(th) + r* // ... etc
// what follows is 24MB of a horrible polynomial from Mathematica
...
denominator = cpow(2,0.3333333333333333) //... etc
return creal(numerator/denominator);
}
我试图确保我正确处理虚数变量。 我已经花了很长的时间寻找不同的职位,但我有以下问题:
- 的值出来为
inf
和nan
时,他们不应该 - 我怀疑这是由于复杂的数字未被正确处理
- This highly rated post指出,
ccos
,csqrt
等应使用复杂的参数 - 我已经在另外尝试了各种命名空间上面:
using complex;
using std::complex;
- 我想也是前面加上
std::complex
和complex::
各功能
免责声明这是我第c/c++
功能,所以请忽略琐碎的问题,除非直接关系到问题
'std :: complex'是一个类,不是一个名称空间。 'cpow'等。您可以使用[reference](http://en.cppreference.com/w/cpp/numeric/complex)来查看C++函数没有前导c并且处于'std'。 – chris
根据OP,我也尝试不包括该行。我将编辑帖子,因为它会分散问题 –
我指的是*我也尝试将std :: complex和complex ::预先添加到每个函数* – chris