我一直在尝试使用英特尔的四精度浮点数。我有以下代码,它返回意外结果。
#include <stdio.h>
#include <math.h>
int print(const char *label, _Quad r) {
int prec = 20;
int width = 46;
char buf[128];
int n = quadmath_snprintf(buf, sizeof buf, "%+-#*.36Qe", width, r);
printf ("%s: %s\n", label, buf);
return 0;
}
int main () {
_Quad x = 3.14159265358979323846264338327950288q;
print("value", x);
print("log", logq(x));
print("log10", log10q(x));
print("cos", cosq(x));
print("sin", sinq(x));
print("sqrt", sqrtq(x));
}
该程序返回以下结果:
value: +3.141592653589793238462643383279502797e+00
log: +7.644623500000000000000000000000000000e+07
log10: -6.174980530000000000000000000000000000e+08
cos: +0.000000000000000000000000000000000000e+00
sin: +0.000000000000000000000000000000000000e+00
sqrt: -1.994699018000000000000000000000000000e+09
看起来四精度文字被正确解释了。但是,函数logq
、log10q
、cosq
和正在返回不正确的结果。sinq
sqrtq
我找到的关于英特尔_Quad
类型的唯一方向是这里。
我在 MacOS 上编译这段代码:
icc -fPIC -wd1572 -Qoption,cpp,--extended_float_type -Wconversion -lquadmath -L/usr/local/Cellar/gcc/10.2.0/lib/gcc/10 test.c
我是否正确使用了四精度数学函数?
另外,我尝试使用本文中描述的函数模式。
libm 函数的四倍精度类似物具有 '__' 前缀(双下划线)和 'q' 后缀。”
但是,这会导致NaN
所有函数都返回。