问题描述
我一直在尝试使用Intel的四精度浮点数。我有以下代码,并且返回了意外的结果。
#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
类型的唯一说明是here。
我正在使用以下命令在MacOS上编译此代码:
icc -fPIC -wd1572 -Qoption,cpp,--extended_float_type -Wconversion -lquadmath -L/usr/local/Cellar/gcc/10.2.0/lib/gcc/10 test.c
我是否正确使用四精度数学函数?
我还尝试使用this post中所述的功能模式。
libm函数的四倍精度类似物带有'__'前缀(双下划线)和'q'后缀。“
但是,这导致为所有函数返回NaN
。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)