c++ - 如何在Intel ICC中启用long double

标签 c++ c intel icc long-double

我在MacOS上,并按照Using the Intel® Math Library指南实现第一个示例:

// real_math.c
#include <stdio.h> 
#include <mathimf.h>

int main() {
 float fp32bits;
 double fp64bits;
 long double fp80bits;
 long double pi_by_four = 3.141592653589793238/4.0;

// pi/4 radians is about 45 degrees
 fp32bits = (float) pi_by_four; // float approximation to pi/4
 fp64bits = (double) pi_by_four; // double approximation to pi/4
 fp80bits = pi_by_four; // long double (extended) approximation to pi/4

// The sin(pi/4) is known to be 1/sqrt(2) or approximately .7071067 
 printf("When x = %8.8f, sinf(x) = %8.8f \n", fp32bits, sinf(fp32bits));
 printf("When x = %16.16f, sin(x) = %16.16f \n", fp64bits, sin(fp64bits));
 printf("When x = %20.20Lf, sinl(x) = %20.20Lf \n", fp80bits, sinl(fp80bits));

 return 0; 
}
按照指南中的指示,我编译为:
icc real_math.c
执行时,我得到:
When x = 0.78539819, sinf(x) = 0.70710677 
When x = 0.7853981633974483, sin(x) = 0.7071067811865475 
When x = 0.78539816339744830952, sinl(x) = 0.00000000000000000000 
我已经进行了广泛的搜索,所有示例似乎都表明这应该是微不足道的。我想念什么?
我试图将-long_double传递给icc,但是没有任何变化。

最佳答案

好的,我知道了。此问题是由于省略1个字符L而导致的我的错误。具体而言,以某种方式在我自己的计算机上的代码中,我有:

 printf("When x = %20.20Lf, sinl(x) = %20.20f \n", fp80bits, sinl(fp80bits));
正确的代码是这样(注意%20.20f%20.20Lf):
 printf("When x = %20.20Lf, sinl(x) = %20.20Lf \n", fp80bits, sinl(fp80bits));
我什至不知道这怎么可能发生,但这是根本原因。
谢谢大家的快速回答,并感谢@PeterCordes将我链接到 godbolt

关于c++ - 如何在Intel ICC中启用long double,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64333966/

相关文章:

C# 与 C++ 通过引用处理传递

c++ - 在二叉搜索树中查找最常用的词

C++ boost/multiprecision : fatal error: mpfr. h: 没有那个文件或目录

c++ - 链接器如何处理具有不同链接的变量?

assembly - 指令 "CVTTPD2PI mm, xmm/m128"可用的 CPUID 是多少?

assembly - 英特尔x86-中断服务程序责任

javascript - 有没有一种方便的方法来搜索和查看特定 JavaScript 方法的实现源代码?

c - sizeof(void*) 和 sizeof(function_type_ptr*) 相等

c++ - OpenCV:如何在图像上应用彩虹渐变图?

x86 - DCU预取器在哪种情况下开始预取?