小编She*_*eng的帖子

g ++优化选项影响sin函数的值

我对libc的"sin"功能有疑问.

#include <cmath>
#include <stdio.h>

int main(int argc, char **argv)
{
    double tt = 6.28318530717958620000; // 2 * M_PI
    double yy = ::sin(tt);

    printf("%.32f\n", yy);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当使用"g ++"编译上述代码而没有任何优化选项时,它将输出"-0.00000000000000024492127076447545".但如果使用"-O3"选项,则输出"-0.00000000000000024492935982947064".

为什么不在没有"-O3"的情况下返回"-0.00000000000000024492935982947064"?提前致谢.

c c++

12
推荐指数
1
解决办法
621
查看次数

标签 统计

c ×1

c++ ×1