浮点计算可以在不同的处理器有什么不同? (+通过C#和C之间双打) [英] Can a calculation of floating point differ on different processors? (+passing doubles between C# and C)

查看:100
本文介绍了浮点计算可以在不同的处理器有什么不同? (+通过C#和C之间双打)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#编写的应用程序调用一些C code为好。在C#code得到一些双作为输入,就可以执行一些计算,它传递给其上执行自己的计算原生层,然后再传递回C#层。

I have an application written in C# that invokes some C code as well. The C# code gets some double as an input, performs some calculations on it, pass it to the native layer that perform its own calculations on it, and then passes back to the C# layer.

如果我运行在不同的机器相同的EXE / DLL文件(全部都是英特尔x64)的,是有可能,最后的结果我会得到的将是在不同的机器有什么不同?

If i run the same exe/dlls on different machines (all of them are x64 by Intel), is it possible that the final result i'll get will be different on different machines?

推荐答案

如果您使用相同的可执行文件(S)的结果应该是相同的。然而,值得注意的是,浮点运算通常由若干持久设置(无穷模式下,舍入模式等)高度可定制的。这意味着相同的浮点指令可产生不同的结果取决于设置的当前组合。如果应用程序确保所有这些设置在开始执行重置为相同的值,然后将结果应该是相同的。但是,如果其中的一些设置不会被重置,或依赖于外部参数(如环境变量),那么在某些情况下,你可能最终在不同的机器观察不同的结果。

If you use the same executable(s) the results should be the same. However, it is worth noting that floating-point calculations are usually highly customizable by a number of persistent settings (infinity mode, rounding mode etc.). This means that the same floating-point instruction can produce different results depending on the current combination of settings. If your application makes sure that all these settings are reset to the same values at the beginning of the execution, then the results should be the same. However, if some of these settings are not reset, or depend on external parameters (like environment variables), then in some circumstances you might end up observing different results on different machines.

这篇关于浮点计算可以在不同的处理器有什么不同? (+通过C#和C之间双打)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆