在Linux,Mac OS X和Windows之间不同的数学舍入行为 [英] Different math rounding behaviour between Linux, Mac OS X and Windows
问题描述
您好,
我开发了一些混合的C / C ++ code,一些密集的数值计算。当Linux和Mac OS X编译我得到的结果非常相似模拟结束后。在Windows中,程序编译,以及,但我得到非常不同的结果,有时程序似乎并没有工作。
I developed some mixed C/C++ code, with some intensive numerical calculations. When compiled in Linux and Mac OS X I get very similar results after the simulation ends. In Windows the program compiles as well but I get very different results and sometimes the program does not seem to work.
我用GNU编译器中的所有系统。有些朋友建议我加-frounding,数学和现在的windows版本似乎工作较稳定,但Linux和OS X中,他们的结果,根本不改变。
I used GNU compilers in all systems. Some friend recommend me to add -frounding-math and now the windows version seems to work more stable, but Linux and Os X, their results, do not change at all.
你能推荐其他选项来赢和Linux / OSX版本之间有更多的一致性?
Could you recommend another options to get more concordance between Win and Linux/OSX versions?
感谢
Pd积。我也试过-O0(不优化)和指定-m32
P.D. I also tried -O0 (no optimizations) and specified -m32
推荐答案
我无法在Windows中执行说话,但英特尔芯片包含80位的浮点寄存器,可以比规定给予更大precision在IEEE-754浮点标准。您可以尝试调用这个例程的的main()的应用程序(基于英特尔芯片平台)的:
I can't speak to the implementation in Windows, but Intel chips contain 80-bit floating point registers, and can give greater precision than that specified in the IEEE-754 floating point standard. You can try calling this routine in the main() of your application (on Intel chip platforms):
inline void fpu_round_to_IEEE_double()
{
unsigned short cw = 0;
_FPU_GETCW(cw); // Get the FPU control word
cw &= ~_FPU_EXTENDED; // mask out '80-bit' register precision
cw |= _FPU_DOUBLE; // Mask in '64-bit' register precision
_FPU_SETCW(cw); // Set the FPU control word
}
我的认为的,这是由@Alok讨论的舍入模式是不同的。
I think this is distinct from the rounding modes discussed by @Alok.
这篇关于在Linux,Mac OS X和Windows之间不同的数学舍入行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!