Rule of thumb to test the equality of two doubles in C#?

后端 未结 6 1920
忘掉有多难
忘掉有多难 2020-12-06 17:00

Let\'s say I have some code that does some floating point arithmetic and stores the values in doubles. Because some values can\'t be represented perfectly in binary, how do

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-06 17:21

    so I'm looking for a good rule of thumb for how to determine the size of the equivalence window.

    Unfortunately, there is no good rule of thumb here. It's entirely determined by the needs of your program. A toy physics simulation may prefer a very high epsilon so that collisions aren't missed. Meanwhile a statistics package would want a low epsilon to be more accurate. You'll just have to tune it to the needs of your app.

提交回复
热议问题