如何确定是浮点不准确? [英] How deterministic is floating point inaccuracy?

查看:109
本文介绍了如何确定是浮点不准确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解,浮点计算精度有问题,也有很多解释为什么的问题。我的问题是,如果我运行相同的计算两次,我总是可以依靠它来产生同样的结果?哪些因素可能影响呢?

I understand that floating point calculations have accuracy issues and there are plenty of questions explaining why. My question is if I run the same calculation twice, can I always rely on it to produce the same result? What factors might affect this?


  • 计算之间的时间?

  • 在CPU的当前状态?

  • 不同的硬件?

  • 语言/平台/操作系统?

  • 太阳耀斑?

我有一个简单的物理模拟,并想记录的会话,以便它们可以被重播。如果计算可以被依靠那么我应该只需要记录的初始状态和任何用户输入,我应该总是能够准确再现最终状态。如果计算不是在开始精确的错误可以通过模拟到底有巨大的影响。

I have a simple physics simulation and would like to record sessions so that they can be replayed. If the calculations can be relied on then I should only need to record the initial state plus any user input and I should always be able to reproduce the final state exactly. If the calculations are not accurate errors at the start may have huge implications by the end of the simulation.

我目前在Silverlight中工作,虽然很想知道,如果这个问题一般可以回答。

I am currently working in Silverlight though would be interested to know if this question can be answered in general.

更新:最初的答案是指出,但显然这不是在所选答案的评论完全讨论明确的。它看起来像我将不得不做一些测试,看看会发生什么。

Update: The initial answers indicate yes, but apparently this isn't entirely clear cut as discussed in the comments for the selected answer. It looks like I will have to do some tests and see what happens.

推荐答案

据我了解你,才能保证相同的结果,只要你在处理相同的指令集和编译器,任何处理器你坚持运行严格的相关标准(即IEEE754)。也就是说,除非你有一个特别混沌系统在计算处理运行之间的任何漂移不太可能导致错误行为。

From what I understand you're only guaranteed identical results provided that you're dealing with the same instruction set and compiler, and that any processors you run on adhere strictly to the relevant standards (ie IEEE754). That said, unless you're dealing with a particularly chaotic system any drift in calculation between runs isn't likely to result in buggy behavior.

这是我所知道的具体陷阱:

Specific gotchas that I'm aware of:

1)一些操作系统允许你设置浮点处理器的模式在破坏兼容性的方式。

1.) some operating systems allow you to set the mode of the floating point processor in ways that break compatibility.

2)浮点运算的中间结果通常使用80位precision注册,但在内存中只有64位。如果程序在改变寄存器的函数内溢出的方式重新编译,它可以相对于其他版本返回不同的结果。大多数平台会给你一个办法,迫使所有结果在内存precision被截断的。

2.) floating point intermediate results often use 80 bit precision in register, but only 64 bit in memory. If a program is recompiled in a way that changes register spilling within a function, it may return different results compared to other versions. Most platforms will give you a way to force all results to be truncated to the in memory precision.

3)标准库函数可以版本之间切换。据我了解,有在GCC 3的这个一定不是寻常遇到的例子VS 4。

3.) standard library functions may change between versions. I gather that there are some not uncommonly encountered examples of this in gcc 3 vs 4.

4)的IEEE本身允许一些二进制重新presentations不同于...具体NaN值,但我不记得细节。

4.) The IEEE itself allows some binary representations to differ... specifically NaN values, but I can't recall the details.

这篇关于如何确定是浮点不准确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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