gpt4 book ai didi

c - 使用英特尔编译器 (icc) 的四精度数字

转载 作者:行者123 更新时间:2023-12-05 06:59:32 26 4
gpt4 key购买 nike

我一直在尝试使用英特尔的四精度 float 。我有以下代码,它返回了意外的结果。

#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

看起来四精度文字被正确解释了。但是,函数 logqlog10qcosqsinqsqrtq 正在返回结果不正确。

我找到的关于 Intel 的 _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 中描述的函数模式.

Quadruple precision analogs of libm functions have '__' prefix (double underscore) and 'q' suffix."

但是,这会导致所有函数返回 NaN

最佳答案

您需要声明函数,并且确实需要“__”前缀。例如:

extern "C" _Quad __logq(_Quad x) ;

这适用于 Windows。看不出为什么它不能在 Mac 上运行。

关于c - 使用英特尔编译器 (icc) 的四精度数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64400327/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com