我正在尝试在GCC中使用quadmath库。我有一个复双精度值,希望将其强制转换为相应的四倍精度复数__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
I get the following error:
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;
如何在这两种类型之间进行转换?