Testing for floating-point value equality: Is there a standard name for the “precision” constant?

别说谁变了你拦得住时间么 提交于 2019-12-25 02:44:27

问题


I just read this nice answer given on how to compare floating-point values for equality. The following (slightly modified by me) is suggested instead of straight-forward comparison to 0:

const double epsilon = 1e-5;

double d = ...;
if (Math.Abs(d) < epsilon)
{
    // d is considered equal to 0.
}

My question is about the name of the variable epsilon1). Is "epsilon" the generally agreed-upon name for specifying the precision of floating-point numbers? (…which is the smallest discriminating difference between any two values which are considered different numbers)?

Since the above code is always easy to understand due to its simplicity, this may seem irrelevant. But I've often stumbled about this naming issue and would like to know, once and for all time, how to name that precision constant, favourably in a way that will let others who read my code know what's intended.

1) I'm aware that epsilon (ε for short, or e) is often used to designate deviations or errors, e.g. in statistics (regression analysis).


回答1:


epsilon is a fine name if you're a mathematician - insignificantlySmallValue is better if you're a long-winded normal person. :)



来源:https://stackoverflow.com/questions/3251435/testing-for-floating-point-value-equality-is-there-a-standard-name-for-the-pre

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