【发布时间】:2015-06-06 21:53:58
【问题描述】:
我正在尝试在我的 C++ 程序中使用 __float128。
但是我在编译它时遇到了麻烦。
这里是简单的c++代码(test.cc):
#include <iostream>
#include <quadmath.h>
using namespace std;
int main(){
__float128 r=0.0q;
__float128 exp_d = expq(12.45q);
cout << "r=" << (double)r << endl;
cout << "exp_d=" << (double)exp_d << endl;
}
我编译这段代码
g++ test.cc -lquadmath -std=c++11
以下错误
error:unable to find numeric literal operator 'operateor"" q'
我该如何解决?
【问题讨论】:
-
签入
quadmath.h以获得operator "" q(__float128)- 这就是它所说的缺失。如果包含运算符时有任何#if/#endif条件,请考虑是否/为什么可能会打错分支。您从哪里读到甚至提供了q后缀?另外,相当多的网站建议使用extern "C" { #include <quadmath.h> }- 可能是链接所必需的,具体取决于您的 quadmath 库版本的年龄。 -
我试过
extern "C" { #include <quadmath.h> },但它不起作用。 -
我使用
strtoflt128()避免了这个编译错误,但我仍然很好奇如何解决这个编译错误。 -
q文字后缀是一个扩展,-std=c++11禁用它。 Compile with-std=gnu++11. -
现在我真的很惊讶人们从哪里得到 128 位浮点数的想法,因为 SIMD 浮点数是 80 位宽。 x86/x64 上是否有任何 128 位浮点硬件支持?