Can a calculation of floating point differ on different processors? (+passing doubles between C# and C)

风格不统一 提交于 2019-12-04 06:08:46

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.

Hardware itself should all should all do it the same way, assuming that they implement IEEE floating point operations, and I think most (all?) do.

http://en.wikipedia.org/wiki/IEEE_754-2008

Most modern hardware is standardised, as is the definition of double. You can check that both are using the same type by checking the memory footprint of each variable - eg sizeof(x).

The should also be some information to poll in float.h.

From what I remember, int tends to be more problematic in consistency terms. Some default to 2 bytes, others to 4, but you could always use long to ensure sizes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!