我正在尝试在GCC中使用quadmath库。我有一个复杂的双精度值,我想要输入相应的四精度复数,__complex128
。以下是最小的(非)木材加工例如:Typecasting std :: complex <double> to __complex128
#include <quadmath.h>
#include <complex>
#include <stdio.h>
using namespace std::complex_literals;
int main(){
std::complex<double> x = 1 + 2i;
std::printf("x = %5.5g + %5.5g\n", x.real(), x.imag());
__complex128 y = 2+2i;
y = x;
return 0;
}
当我尝试编译此代码
g++ test.cpp -lquadmath -o test
我得到以下错误:
test.cpp:10:6: error: cannot convert 'std::complex<double>' to '__complex128 {aka __complex__ __float128}' in assignment
y = x;
如果我尝试更换具有明确类型转换的分配线,
y = (__complex128) x;
我收到了类似的错误
test.cpp:10:21: error: invalid cast from type 'std::complex<double>' to type '__complex128 {aka __complex__ __float128}'
y = (__complex128) x;
一个人怎么这两种类型之间的转换?
谢谢!那就是诀窍。我不知道__real__和__imag__扩展名。俏皮。 – Jeff